diff options
author | Siva Chandra <sivachandra@google.com> | 2016-02-04 18:38:35 +0000 |
---|---|---|
committer | Siva Chandra <sivachandra@google.com> | 2016-02-04 18:38:35 +0000 |
commit | 375882dddb92b4cf9fac72b3388b9c4af35d8ba6 (patch) | |
tree | ef1bee8ec19899ee4edb351549bffc40a1f62135 /lldb/source/Expression/ExpressionSourceCode.cpp | |
parent | 76c48e0e704ef72f37766ef12b3fa1a924c33ad8 (diff) | |
download | bcm5719-llvm-375882dddb92b4cf9fac72b3388b9c4af35d8ba6.tar.gz bcm5719-llvm-375882dddb92b4cf9fac72b3388b9c4af35d8ba6.zip |
Use an artifical namespace so that member vars do not hide local vars.
Summary:
While evaluating expressions when stopped in a class method, there was a
problem of member variables hiding local variables. This was happening
because, in the context of a method, clang already knew about member
variables with their name and assumed that they were the only variables
with those names in scope. Consequently, clang never checks with LLDB
about the possibility of local variables with the same name and goes
wrong. This change addresses the problem by using an artificial
namespace "$__lldb_local_vars". All local variables in scope are
declared in the "$__lldb_expr" method as follows:
using $__lldb_local_vars::<local var 1>;
using $__lldb_local_vars::<local var 2>;
...
This hides the member variables with the same name and forces clang to
enquire about the variables which it thinks are declared in
$__lldb_local_vars. When LLDB notices that clang is enquiring about
variables in $__lldb_local_vars, it looks up local vars and conveys
their information if found. This way, member variables do not hide local
variables, leading to correct evaluation of expressions.
A point to keep in mind is that the above solution does not solve the
problem for one specific case:
namespace N
{
int a;
}
class A
{
public:
void Method();
int a;
};
void
A::Method()
{
using N::a;
...
// Since the above solution only touches locals, it does not
// force clang to enquire about "a" coming from namespace N.
}
Reviewers: clayborg, spyffe
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D16746
llvm-svn: 259810
Diffstat (limited to 'lldb/source/Expression/ExpressionSourceCode.cpp')
-rw-r--r-- | lldb/source/Expression/ExpressionSourceCode.cpp | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/lldb/source/Expression/ExpressionSourceCode.cpp b/lldb/source/Expression/ExpressionSourceCode.cpp index 93bac62c43c..13fdaf8dfeb 100644 --- a/lldb/source/Expression/ExpressionSourceCode.cpp +++ b/lldb/source/Expression/ExpressionSourceCode.cpp @@ -16,7 +16,9 @@ #include "lldb/Symbol/DebugMacros.h" #include "lldb/Symbol/Block.h" #include "lldb/Symbol/TypeSystem.h" +#include "lldb/Symbol/VariableList.h" #include "lldb/Target/ExecutionContext.h" +#include "lldb/Target/Language.h" #include "lldb/Target/Platform.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" @@ -175,6 +177,21 @@ AddMacros(const DebugMacros *dm, CompileUnit *comp_unit, AddMacroState &state, S } } +static void +AddLocalVariableDecls(const lldb::VariableListSP &var_list_sp, StreamString &stream) +{ + for (size_t i = 0; i < var_list_sp->GetSize(); i++) + { + lldb::VariableSP var_sp = var_list_sp->GetVariableAtIndex(i); + + ConstString var_name = var_sp->GetName(); + if (var_name == ConstString("this")) + continue; + + stream.Printf("using $__lldb_local_vars::%s;\n", var_name.AsCString()); + } +} + bool ExpressionSourceCode::GetText (std::string &text, lldb::LanguageType wrapping_language, bool const_object, bool static_method, ExecutionContext &exe_ctx) const { const char *target_specific_defines = "typedef signed char BOOL;\n"; @@ -239,6 +256,7 @@ bool ExpressionSourceCode::GetText (std::string &text, lldb::LanguageType wrappi } StreamString debug_macros_stream; + StreamString lldb_local_var_decls; if (StackFrame *frame = exe_ctx.GetFramePtr()) { const SymbolContext &sc = frame->GetSymbolContext( @@ -253,8 +271,15 @@ bool ExpressionSourceCode::GetText (std::string &text, lldb::LanguageType wrappi AddMacros(dm, sc.comp_unit, state, debug_macros_stream); } } + + ConstString object_name; + if (Language::LanguageIsCPlusPlus(frame->GetLanguage())) + { + lldb::VariableListSP var_list_sp = frame->GetInScopeVariableList(false); + AddLocalVariableDecls(var_list_sp, lldb_local_var_decls); + } } - + if (m_wrap) { switch (wrapping_language) @@ -284,19 +309,23 @@ bool ExpressionSourceCode::GetText (std::string &text, lldb::LanguageType wrappi wrap_stream.Printf("void \n" "%s(void *$__lldb_arg) \n" "{ \n" + " %s; \n" " %s; \n" "} \n", m_name.c_str(), + lldb_local_var_decls.GetData(), m_body.c_str()); break; case lldb::eLanguageTypeC_plus_plus: wrap_stream.Printf("void \n" "$__lldb_class::%s(void *$__lldb_arg) %s\n" "{ \n" + " %s; \n" " %s; \n" "} \n", m_name.c_str(), (const_object ? "const" : ""), + lldb_local_var_decls.GetData(), m_body.c_str()); break; case lldb::eLanguageTypeObjC: @@ -339,6 +368,6 @@ bool ExpressionSourceCode::GetText (std::string &text, lldb::LanguageType wrappi { text.append(m_body); } - + return true; } |