llvm-project/lldb/source/API/SBExpressionOptions.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

259 lines
6.6 KiB
C++
Raw Normal View History

//===-- SBExpressionOptions.cpp -------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lldb/API/SBExpressionOptions.h"
#include "Utils.h"
#include "lldb/API/SBStream.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/Instrumentation.h"
using namespace lldb;
using namespace lldb_private;
2012-10-17 06:58:25 +08:00
SBExpressionOptions::SBExpressionOptions()
: m_opaque_up(new EvaluateExpressionOptions()) {
LLDB_INSTRUMENT_VA(this);
}
SBExpressionOptions::SBExpressionOptions(const SBExpressionOptions &rhs) {
LLDB_INSTRUMENT_VA(this, rhs);
m_opaque_up = clone(rhs.m_opaque_up);
}
const SBExpressionOptions &SBExpressionOptions::
operator=(const SBExpressionOptions &rhs) {
LLDB_INSTRUMENT_VA(this, rhs);
if (this != &rhs)
m_opaque_up = clone(rhs.m_opaque_up);
2022-01-10 14:54:08 +08:00
return *this;
}
SBExpressionOptions::~SBExpressionOptions() = default;
2012-10-17 06:58:25 +08:00
bool SBExpressionOptions::GetCoerceResultToId() const {
LLDB_INSTRUMENT_VA(this);
return m_opaque_up->DoesCoerceToId();
}
2012-10-17 06:58:25 +08:00
void SBExpressionOptions::SetCoerceResultToId(bool coerce) {
LLDB_INSTRUMENT_VA(this, coerce);
m_opaque_up->SetCoerceToId(coerce);
}
2012-10-17 06:58:25 +08:00
bool SBExpressionOptions::GetUnwindOnError() const {
LLDB_INSTRUMENT_VA(this);
return m_opaque_up->DoesUnwindOnError();
}
void SBExpressionOptions::SetUnwindOnError(bool unwind) {
LLDB_INSTRUMENT_VA(this, unwind);
m_opaque_up->SetUnwindOnError(unwind);
}
bool SBExpressionOptions::GetIgnoreBreakpoints() const {
LLDB_INSTRUMENT_VA(this);
return m_opaque_up->DoesIgnoreBreakpoints();
}
void SBExpressionOptions::SetIgnoreBreakpoints(bool ignore) {
LLDB_INSTRUMENT_VA(this, ignore);
m_opaque_up->SetIgnoreBreakpoints(ignore);
}
2012-10-17 06:58:25 +08:00
lldb::DynamicValueType SBExpressionOptions::GetFetchDynamicValue() const {
LLDB_INSTRUMENT_VA(this);
return m_opaque_up->GetUseDynamic();
}
2012-10-17 06:58:25 +08:00
void SBExpressionOptions::SetFetchDynamicValue(lldb::DynamicValueType dynamic) {
LLDB_INSTRUMENT_VA(this, dynamic);
m_opaque_up->SetUseDynamic(dynamic);
}
2012-10-17 06:58:25 +08:00
uint32_t SBExpressionOptions::GetTimeoutInMicroSeconds() const {
LLDB_INSTRUMENT_VA(this);
return m_opaque_up->GetTimeout() ? m_opaque_up->GetTimeout()->count() : 0;
}
2012-10-17 06:58:25 +08:00
void SBExpressionOptions::SetTimeoutInMicroSeconds(uint32_t timeout) {
LLDB_INSTRUMENT_VA(this, timeout);
m_opaque_up->SetTimeout(timeout == 0 ? Timeout<std::micro>(llvm::None)
: std::chrono::microseconds(timeout));
}
uint32_t SBExpressionOptions::GetOneThreadTimeoutInMicroSeconds() const {
LLDB_INSTRUMENT_VA(this);
return m_opaque_up->GetOneThreadTimeout()
? m_opaque_up->GetOneThreadTimeout()->count()
: 0;
}
void SBExpressionOptions::SetOneThreadTimeoutInMicroSeconds(uint32_t timeout) {
LLDB_INSTRUMENT_VA(this, timeout);
m_opaque_up->SetOneThreadTimeout(timeout == 0
? Timeout<std::micro>(llvm::None)
: std::chrono::microseconds(timeout));
}
2012-10-17 06:58:25 +08:00
bool SBExpressionOptions::GetTryAllThreads() const {
LLDB_INSTRUMENT_VA(this);
return m_opaque_up->GetTryAllThreads();
}
2012-10-17 06:58:25 +08:00
void SBExpressionOptions::SetTryAllThreads(bool run_others) {
LLDB_INSTRUMENT_VA(this, run_others);
m_opaque_up->SetTryAllThreads(run_others);
}
bool SBExpressionOptions::GetStopOthers() const {
LLDB_INSTRUMENT_VA(this);
return m_opaque_up->GetStopOthers();
}
void SBExpressionOptions::SetStopOthers(bool run_others) {
LLDB_INSTRUMENT_VA(this, run_others);
m_opaque_up->SetStopOthers(run_others);
}
bool SBExpressionOptions::GetTrapExceptions() const {
LLDB_INSTRUMENT_VA(this);
return m_opaque_up->GetTrapExceptions();
}
void SBExpressionOptions::SetTrapExceptions(bool trap_exceptions) {
LLDB_INSTRUMENT_VA(this, trap_exceptions);
m_opaque_up->SetTrapExceptions(trap_exceptions);
}
Initial merge of some of the iOS 8 / Mac OS X Yosemite specific lldb support. I'll be doing more testing & cleanup but I wanted to get the initial checkin done. This adds a new SBExpressionOptions::SetLanguage API for selecting a language of an expression. I added adds a new SBThread::GetInfoItemByPathString for retriving information about a thread from that thread's StructuredData. I added a new StructuredData class for representing key-value/array/dictionary information (e.g. JSON formatted data). Helper functions to read JSON and create a StructuredData object, and to print a StructuredData object in JSON format are included. A few Cocoa / Cocoa Touch data formatters were updated by Enrico to track changes in iOS 8 / Yosemite. Before we query a thread's extended information, the system runtime may provide hints to the remote debug stub that it will use to retrieve values out of runtime structures. I added a new SystemRuntime method AddThreadExtendedInfoPacketHints which allows the SystemRuntime to add key-value type data to the initial request that we send to the remote stub. The thread-format formatter string can now retrieve values out of a thread's extended info structured data. The default thread-format string picks up two of these - thread.info.activity.name and thread.info.trace_messages. I added a new "jThreadExtendedInfo" packet in debugserver; I will add documentation to the lldb-gdb-remote.txt doc soon. It accepts JSON formatted arguments (most importantly, "thread":threadnum) and it returns a variety of information regarding the thread to lldb in JSON format. This JSON return is scanned into a StructuredData object that is associated with the thread; UI layers can query the thread's StructuredData to see if key-values are present, and if so, show them to the user. These key-values are likely to be specific to different targets with some commonality among many targets. For instance, many targets will be able to advertise the pthread_t value for a thread. I added an initial rough cut of "thread info" command which will print the information about a thread from the jThreadExtendedInfo result. I need to do more work to make this format reasonably. Han Ming added calls into the pmenergy and pmsample libraries if debugserver is run on Mac OS X Yosemite to get information about the inferior's power use. I added support to debugserver for gathering the Genealogy information about threads, if it exists, and returning it in the jThreadExtendedInfo JSON result. llvm-svn: 210874
2014-06-13 10:37:02 +08:00
void SBExpressionOptions::SetLanguage(lldb::LanguageType language) {
LLDB_INSTRUMENT_VA(this, language);
m_opaque_up->SetLanguage(language);
Initial merge of some of the iOS 8 / Mac OS X Yosemite specific lldb support. I'll be doing more testing & cleanup but I wanted to get the initial checkin done. This adds a new SBExpressionOptions::SetLanguage API for selecting a language of an expression. I added adds a new SBThread::GetInfoItemByPathString for retriving information about a thread from that thread's StructuredData. I added a new StructuredData class for representing key-value/array/dictionary information (e.g. JSON formatted data). Helper functions to read JSON and create a StructuredData object, and to print a StructuredData object in JSON format are included. A few Cocoa / Cocoa Touch data formatters were updated by Enrico to track changes in iOS 8 / Yosemite. Before we query a thread's extended information, the system runtime may provide hints to the remote debug stub that it will use to retrieve values out of runtime structures. I added a new SystemRuntime method AddThreadExtendedInfoPacketHints which allows the SystemRuntime to add key-value type data to the initial request that we send to the remote stub. The thread-format formatter string can now retrieve values out of a thread's extended info structured data. The default thread-format string picks up two of these - thread.info.activity.name and thread.info.trace_messages. I added a new "jThreadExtendedInfo" packet in debugserver; I will add documentation to the lldb-gdb-remote.txt doc soon. It accepts JSON formatted arguments (most importantly, "thread":threadnum) and it returns a variety of information regarding the thread to lldb in JSON format. This JSON return is scanned into a StructuredData object that is associated with the thread; UI layers can query the thread's StructuredData to see if key-values are present, and if so, show them to the user. These key-values are likely to be specific to different targets with some commonality among many targets. For instance, many targets will be able to advertise the pthread_t value for a thread. I added an initial rough cut of "thread info" command which will print the information about a thread from the jThreadExtendedInfo result. I need to do more work to make this format reasonably. Han Ming added calls into the pmenergy and pmsample libraries if debugserver is run on Mac OS X Yosemite to get information about the inferior's power use. I added support to debugserver for gathering the Genealogy information about threads, if it exists, and returning it in the jThreadExtendedInfo JSON result. llvm-svn: 210874
2014-06-13 10:37:02 +08:00
}
void SBExpressionOptions::SetCancelCallback(
lldb::ExpressionCancelCallback callback, void *baton) {
LLDB_INSTRUMENT_VA(this, callback, baton);
m_opaque_up->SetCancelCallback(callback, baton);
}
bool SBExpressionOptions::GetGenerateDebugInfo() {
LLDB_INSTRUMENT_VA(this);
return m_opaque_up->GetGenerateDebugInfo();
}
void SBExpressionOptions::SetGenerateDebugInfo(bool b) {
LLDB_INSTRUMENT_VA(this, b);
return m_opaque_up->SetGenerateDebugInfo(b);
}
bool SBExpressionOptions::GetSuppressPersistentResult() {
LLDB_INSTRUMENT_VA(this);
return m_opaque_up->GetResultIsInternal();
}
void SBExpressionOptions::SetSuppressPersistentResult(bool b) {
LLDB_INSTRUMENT_VA(this, b);
return m_opaque_up->SetResultIsInternal(b);
}
2015-05-28 06:32:39 +08:00
const char *SBExpressionOptions::GetPrefix() const {
LLDB_INSTRUMENT_VA(this);
return m_opaque_up->GetPrefix();
2015-05-28 06:32:39 +08:00
}
void SBExpressionOptions::SetPrefix(const char *prefix) {
LLDB_INSTRUMENT_VA(this, prefix);
return m_opaque_up->SetPrefix(prefix);
2015-05-28 06:32:39 +08:00
}
bool SBExpressionOptions::GetAutoApplyFixIts() {
LLDB_INSTRUMENT_VA(this);
return m_opaque_up->GetAutoApplyFixIts();
}
void SBExpressionOptions::SetAutoApplyFixIts(bool b) {
LLDB_INSTRUMENT_VA(this, b);
return m_opaque_up->SetAutoApplyFixIts(b);
}
[lldb] Add option to retry Fix-Its multiple times to failed expressions Summary: Usually when Clang emits an error Fix-It it does two things. It emits the diagnostic and then it fixes the currently generated AST to reflect the applied Fix-It. While emitting the diagnostic is easy to implement, fixing the currently generated AST is often tricky. That causes that some Fix-Its just keep the AST as-is or abort the parsing process entirely. Once the parser stopped, any Fix-Its for the rest of the expression are not detected and when the user manually applies the Fix-It, the next expression will just produce a new Fix-It. This is often occurring with quickly made Fix-Its that are just used to bridge temporary API changes and that often are not worth implementing a proper API fixup in addition to the diagnostic. To still give some kind of reasonable user-experience for users that have these Fix-Its and rely on them to fix their expressions, this patch adds the ability to retry parsing with applied Fix-Its multiple time to give the normal Fix-It experience where things Clang knows how to fix are not causing actual expression error (at least when automatically applying Fix-Its is activated). The way this is implemented is just by having another setting in the expression options that specify how often we should try applying Fix-Its and then reparse the expression. The default setting is still 1 for everyone so this should not affect the speed in which we fail to parse expressions. Reviewers: jingham, JDevlieghere, friss, shafik Reviewed By: shafik Subscribers: shafik, abidh Differential Revision: https://reviews.llvm.org/D77214
2020-04-06 17:08:12 +08:00
uint64_t SBExpressionOptions::GetRetriesWithFixIts() {
LLDB_INSTRUMENT_VA(this);
[lldb] Add option to retry Fix-Its multiple times to failed expressions Summary: Usually when Clang emits an error Fix-It it does two things. It emits the diagnostic and then it fixes the currently generated AST to reflect the applied Fix-It. While emitting the diagnostic is easy to implement, fixing the currently generated AST is often tricky. That causes that some Fix-Its just keep the AST as-is or abort the parsing process entirely. Once the parser stopped, any Fix-Its for the rest of the expression are not detected and when the user manually applies the Fix-It, the next expression will just produce a new Fix-It. This is often occurring with quickly made Fix-Its that are just used to bridge temporary API changes and that often are not worth implementing a proper API fixup in addition to the diagnostic. To still give some kind of reasonable user-experience for users that have these Fix-Its and rely on them to fix their expressions, this patch adds the ability to retry parsing with applied Fix-Its multiple time to give the normal Fix-It experience where things Clang knows how to fix are not causing actual expression error (at least when automatically applying Fix-Its is activated). The way this is implemented is just by having another setting in the expression options that specify how often we should try applying Fix-Its and then reparse the expression. The default setting is still 1 for everyone so this should not affect the speed in which we fail to parse expressions. Reviewers: jingham, JDevlieghere, friss, shafik Reviewed By: shafik Subscribers: shafik, abidh Differential Revision: https://reviews.llvm.org/D77214
2020-04-06 17:08:12 +08:00
return m_opaque_up->GetRetriesWithFixIts();
}
void SBExpressionOptions::SetRetriesWithFixIts(uint64_t retries) {
LLDB_INSTRUMENT_VA(this, retries);
[lldb] Add option to retry Fix-Its multiple times to failed expressions Summary: Usually when Clang emits an error Fix-It it does two things. It emits the diagnostic and then it fixes the currently generated AST to reflect the applied Fix-It. While emitting the diagnostic is easy to implement, fixing the currently generated AST is often tricky. That causes that some Fix-Its just keep the AST as-is or abort the parsing process entirely. Once the parser stopped, any Fix-Its for the rest of the expression are not detected and when the user manually applies the Fix-It, the next expression will just produce a new Fix-It. This is often occurring with quickly made Fix-Its that are just used to bridge temporary API changes and that often are not worth implementing a proper API fixup in addition to the diagnostic. To still give some kind of reasonable user-experience for users that have these Fix-Its and rely on them to fix their expressions, this patch adds the ability to retry parsing with applied Fix-Its multiple time to give the normal Fix-It experience where things Clang knows how to fix are not causing actual expression error (at least when automatically applying Fix-Its is activated). The way this is implemented is just by having another setting in the expression options that specify how often we should try applying Fix-Its and then reparse the expression. The default setting is still 1 for everyone so this should not affect the speed in which we fail to parse expressions. Reviewers: jingham, JDevlieghere, friss, shafik Reviewed By: shafik Subscribers: shafik, abidh Differential Revision: https://reviews.llvm.org/D77214
2020-04-06 17:08:12 +08:00
return m_opaque_up->SetRetriesWithFixIts(retries);
}
bool SBExpressionOptions::GetTopLevel() {
LLDB_INSTRUMENT_VA(this);
return m_opaque_up->GetExecutionPolicy() == eExecutionPolicyTopLevel;
}
void SBExpressionOptions::SetTopLevel(bool b) {
LLDB_INSTRUMENT_VA(this, b);
m_opaque_up->SetExecutionPolicy(b ? eExecutionPolicyTopLevel
: m_opaque_up->default_execution_policy);
}
bool SBExpressionOptions::GetAllowJIT() {
LLDB_INSTRUMENT_VA(this);
return m_opaque_up->GetExecutionPolicy() != eExecutionPolicyNever;
}
void SBExpressionOptions::SetAllowJIT(bool allow) {
LLDB_INSTRUMENT_VA(this, allow);
m_opaque_up->SetExecutionPolicy(allow ? m_opaque_up->default_execution_policy
: eExecutionPolicyNever);
}
EvaluateExpressionOptions *SBExpressionOptions::get() const {
return m_opaque_up.get();
}
EvaluateExpressionOptions &SBExpressionOptions::ref() const {
return *(m_opaque_up.get());
}