Skip to content

Commit

Permalink
Merged master:e8bcf4ef07c into amd-gfx:6c9d03142c4
Browse files Browse the repository at this point in the history
Local branch amd-gfx 6c9d031 Merged master:e75efcc3c1a into amd-gfx:5370b73ab7f
Remote branch master e8bcf4e [DebugInfo] Add use of truncating data extractor to debug line parsing
  • Loading branch information
Sw authored and Sw committed Jun 1, 2020
2 parents 6c9d031 + e8bcf4e commit 8d98476
Show file tree
Hide file tree
Showing 48 changed files with 814 additions and 368 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// CHECK-NEXT: [[B_ADDR:%.*]] = alloca i32, align 4
// CHECK-NEXT: store i64 [[A:%.*]], i64* [[A_ADDR]], align 8
// CHECK-NEXT: store i32 [[B:%.*]], i32* [[B_ADDR]], align 4
// CHECK-NEXT: [[NAMELESS0:%.*]] = load i64, i64* [[A_ADDR]], align 8
// CHECK-NEXT: [[NAMELESS1:%.*]] = load i32, i32* [[B_ADDR]], align 4
// CHECK-NEXT: [[CONV:%.*]] = sext i32 [[NAMELESS1]] to i64
// CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[NAMELESS0]], [[CONV]]
// CHECK-NEXT: [[TMP0:%.*]] = load i64, i64* [[A_ADDR]], align 8
// CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[B_ADDR]], align 4
// CHECK-NEXT: [[CONV:%.*]] = sext i32 [[TMP1]] to i64
// CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[TMP0]], [[CONV]]
// CHECK-NEXT: ret i64 [[ADD]]
//
long test(long a, int b) {
Expand All @@ -27,12 +27,12 @@ long test(long a, int b) {
// CHECK-NEXT: store i64 [[A:%.*]], i64* [[A_ADDR]], align 8
// CHECK-NEXT: store i32 [[B:%.*]], i32* [[B_ADDR]], align 4
// CHECK-NEXT: store i32 [[C:%.*]], i32* [[C_ADDR]], align 4
// CHECK-NEXT: [[NAMELESS0:%.*]] = load i64, i64* [[A_ADDR]], align 8
// CHECK-NEXT: [[NAMELESS1:%.*]] = load i32, i32* [[B_ADDR]], align 4
// CHECK-NEXT: [[CONV:%.*]] = sext i32 [[NAMELESS1]] to i64
// CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[NAMELESS0]], [[CONV]]
// CHECK-NEXT: [[NAMELESS2:%.*]] = load i32, i32* [[C_ADDR]], align 4
// CHECK-NEXT: [[CONV1:%.*]] = sext i32 [[NAMELESS2]] to i64
// CHECK-NEXT: [[TMP0:%.*]] = load i64, i64* [[A_ADDR]], align 8
// CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[B_ADDR]], align 4
// CHECK-NEXT: [[CONV:%.*]] = sext i32 [[TMP1]] to i64
// CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[TMP0]], [[CONV]]
// CHECK-NEXT: [[TMP2:%.*]] = load i32, i32* [[C_ADDR]], align 4
// CHECK-NEXT: [[CONV1:%.*]] = sext i32 [[TMP2]] to i64
// CHECK-NEXT: [[ADD2:%.*]] = add nsw i64 [[ADD]], [[CONV1]]
// CHECK-NEXT: ret i64 [[ADD2]]
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
// CHECK-NEXT: [[B_ADDR:%.*]] = alloca i32, align 4
// CHECK-NEXT: store i64 [[A]], i64* [[A_ADDR]], align 8
// CHECK-NEXT: store i32 [[B]], i32* [[B_ADDR]], align 4
// CHECK-NEXT: [[NAMELESS0:%.*]] = load i64, i64* [[A_ADDR]], align 8
// CHECK-NEXT: [[NAMELESS1:%.*]] = load i32, i32* [[B_ADDR]], align 4
// CHECK-NEXT: [[CONV:%.*]] = sext i32 [[NAMELESS1]] to i64
// CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[NAMELESS0]], [[CONV]]
// CHECK-NEXT: [[TMP0:%.*]] = load i64, i64* [[A_ADDR]], align 8
// CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[B_ADDR]], align 4
// CHECK-NEXT: [[CONV:%.*]] = sext i32 [[TMP1]] to i64
// CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[TMP0]], [[CONV]]
// CHECK-NEXT: ret i64 [[ADD]]
//
long test(long a, int b) {
Expand All @@ -29,12 +29,12 @@ long test(long a, int b) {
// CHECK-NEXT: store i64 [[A]], i64* [[A_ADDR]], align 8
// CHECK-NEXT: store i32 [[B]], i32* [[B_ADDR]], align 4
// CHECK-NEXT: store i32 [[C]], i32* [[C_ADDR]], align 4
// CHECK-NEXT: [[NAMELESS0:%.*]] = load i64, i64* [[A_ADDR]], align 8
// CHECK-NEXT: [[NAMELESS1:%.*]] = load i32, i32* [[B_ADDR]], align 4
// CHECK-NEXT: [[CONV:%.*]] = sext i32 [[NAMELESS1]] to i64
// CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[NAMELESS0]], [[CONV]]
// CHECK-NEXT: [[NAMELESS2:%.*]] = load i32, i32* [[C_ADDR]], align 4
// CHECK-NEXT: [[CONV1:%.*]] = sext i32 [[NAMELESS2]] to i64
// CHECK-NEXT: [[TMP0:%.*]] = load i64, i64* [[A_ADDR]], align 8
// CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[B_ADDR]], align 4
// CHECK-NEXT: [[CONV:%.*]] = sext i32 [[TMP1]] to i64
// CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[TMP0]], [[CONV]]
// CHECK-NEXT: [[TMP2:%.*]] = load i32, i32* [[C_ADDR]], align 4
// CHECK-NEXT: [[CONV1:%.*]] = sext i32 [[TMP2]] to i64
// CHECK-NEXT: [[ADD2:%.*]] = add nsw i64 [[ADD]], [[CONV1]]
// CHECK-NEXT: ret i64 [[ADD2]]
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ static void AddMacros(const DebugMacros *dm, CompileUnit *comp_unit,

lldb_private::ClangExpressionSourceCode::ClangExpressionSourceCode(
llvm::StringRef filename, llvm::StringRef name, llvm::StringRef prefix,
llvm::StringRef body, Wrapping wrap)
: ExpressionSourceCode(name, prefix, body, wrap) {
llvm::StringRef body, Wrapping wrap, WrapKind wrap_kind)
: ExpressionSourceCode(name, prefix, body, wrap), m_wrap_kind(wrap_kind) {
// Use #line markers to pretend that we have a single-line source file
// containing only the user expression. This will hide our wrapper code
// from the user when we render diagnostics with Clang.
Expand Down Expand Up @@ -261,10 +261,9 @@ TokenVerifier::TokenVerifier(std::string body) {
}
}

static void AddLocalVariableDecls(const lldb::VariableListSP &var_list_sp,
StreamString &stream,
const std::string &expr,
lldb::LanguageType wrapping_language) {
void ClangExpressionSourceCode::AddLocalVariableDecls(
const lldb::VariableListSP &var_list_sp, StreamString &stream,
const std::string &expr) const {
TokenVerifier tokens(expr);

for (size_t i = 0; i < var_list_sp->GetSize(); i++) {
Expand All @@ -281,23 +280,21 @@ static void AddLocalVariableDecls(const lldb::VariableListSP &var_list_sp,
if (!expr.empty() && !tokens.hasToken(var_name.GetStringRef()))
continue;

if ((var_name == "self" || var_name == "_cmd") &&
(wrapping_language == lldb::eLanguageTypeObjC ||
wrapping_language == lldb::eLanguageTypeObjC_plus_plus))
const bool is_objc = m_wrap_kind == WrapKind::ObjCInstanceMethod ||
m_wrap_kind == WrapKind::ObjCStaticMethod;
if ((var_name == "self" || var_name == "_cmd") && is_objc)
continue;

if (var_name == "this" &&
wrapping_language == lldb::eLanguageTypeC_plus_plus)
if (var_name == "this" && m_wrap_kind == WrapKind::CppMemberFunction)
continue;

stream.Printf("using $__lldb_local_vars::%s;\n", var_name.AsCString());
}
}

bool ClangExpressionSourceCode::GetText(
std::string &text, lldb::LanguageType wrapping_language, bool static_method,
ExecutionContext &exe_ctx, bool add_locals, bool force_add_all_locals,
llvm::ArrayRef<std::string> modules) const {
std::string &text, ExecutionContext &exe_ctx, bool add_locals,
bool force_add_all_locals, llvm::ArrayRef<std::string> modules) const {
const char *target_specific_defines = "typedef signed char BOOL;\n";
std::string module_macros;

Expand Down Expand Up @@ -374,21 +371,11 @@ bool ClangExpressionSourceCode::GetText(
lldb::VariableListSP var_list_sp =
frame->GetInScopeVariableList(false, true);
AddLocalVariableDecls(var_list_sp, lldb_local_var_decls,
force_add_all_locals ? "" : m_body,
wrapping_language);
force_add_all_locals ? "" : m_body);
}
}

if (m_wrap) {
switch (wrapping_language) {
default:
return false;
case lldb::eLanguageTypeC:
case lldb::eLanguageTypeC_plus_plus:
case lldb::eLanguageTypeObjC:
break;
}

// Generate a list of @import statements that will import the specified
// module into our expression.
std::string module_imports;
Expand All @@ -407,22 +394,12 @@ bool ClangExpressionSourceCode::GetText(
// First construct a tagged form of the user expression so we can find it
// later:
std::string tagged_body;
switch (wrapping_language) {
default:
tagged_body = m_body;
break;
case lldb::eLanguageTypeC:
case lldb::eLanguageTypeC_plus_plus:
case lldb::eLanguageTypeObjC:
tagged_body.append(m_start_marker);
tagged_body.append(m_body);
tagged_body.append(m_end_marker);
break;
}
switch (wrapping_language) {
default:
break;
case lldb::eLanguageTypeC:
tagged_body.append(m_start_marker);
tagged_body.append(m_body);
tagged_body.append(m_end_marker);

switch (m_wrap_kind) {
case WrapKind::Function:
wrap_stream.Printf("%s"
"void \n"
"%s(void *$__lldb_arg) \n"
Expand All @@ -433,7 +410,7 @@ bool ClangExpressionSourceCode::GetText(
module_imports.c_str(), m_name.c_str(),
lldb_local_var_decls.GetData(), tagged_body.c_str());
break;
case lldb::eLanguageTypeC_plus_plus:
case WrapKind::CppMemberFunction:
wrap_stream.Printf("%s"
"void \n"
"$__lldb_class::%s(void *$__lldb_arg) \n"
Expand All @@ -444,38 +421,38 @@ bool ClangExpressionSourceCode::GetText(
module_imports.c_str(), m_name.c_str(),
lldb_local_var_decls.GetData(), tagged_body.c_str());
break;
case lldb::eLanguageTypeObjC:
if (static_method) {
wrap_stream.Printf(
"%s"
"@interface $__lldb_objc_class ($__lldb_category) \n"
"+(void)%s:(void *)$__lldb_arg; \n"
"@end \n"
"@implementation $__lldb_objc_class ($__lldb_category) \n"
"+(void)%s:(void *)$__lldb_arg \n"
"{ \n"
" %s; \n"
"%s"
"} \n"
"@end \n",
module_imports.c_str(), m_name.c_str(), m_name.c_str(),
lldb_local_var_decls.GetData(), tagged_body.c_str());
} else {
wrap_stream.Printf(
"%s"
"@interface $__lldb_objc_class ($__lldb_category) \n"
"-(void)%s:(void *)$__lldb_arg; \n"
"@end \n"
"@implementation $__lldb_objc_class ($__lldb_category) \n"
"-(void)%s:(void *)$__lldb_arg \n"
"{ \n"
" %s; \n"
"%s"
"} \n"
"@end \n",
module_imports.c_str(), m_name.c_str(), m_name.c_str(),
lldb_local_var_decls.GetData(), tagged_body.c_str());
}
case WrapKind::ObjCInstanceMethod:
wrap_stream.Printf(
"%s"
"@interface $__lldb_objc_class ($__lldb_category) \n"
"-(void)%s:(void *)$__lldb_arg; \n"
"@end \n"
"@implementation $__lldb_objc_class ($__lldb_category) \n"
"-(void)%s:(void *)$__lldb_arg \n"
"{ \n"
" %s; \n"
"%s"
"} \n"
"@end \n",
module_imports.c_str(), m_name.c_str(), m_name.c_str(),
lldb_local_var_decls.GetData(), tagged_body.c_str());
break;

case WrapKind::ObjCStaticMethod:
wrap_stream.Printf(
"%s"
"@interface $__lldb_objc_class ($__lldb_category) \n"
"+(void)%s:(void *)$__lldb_arg; \n"
"@end \n"
"@implementation $__lldb_objc_class ($__lldb_category) \n"
"+(void)%s:(void *)$__lldb_arg \n"
"{ \n"
" %s; \n"
"%s"
"} \n"
"@end \n",
module_imports.c_str(), m_name.c_str(), m_name.c_str(),
lldb_local_var_decls.GetData(), tagged_body.c_str());
break;
}

Expand All @@ -488,17 +465,7 @@ bool ClangExpressionSourceCode::GetText(
}

bool ClangExpressionSourceCode::GetOriginalBodyBounds(
std::string transformed_text, lldb::LanguageType wrapping_language,
size_t &start_loc, size_t &end_loc) {
switch (wrapping_language) {
default:
return false;
case lldb::eLanguageTypeC:
case lldb::eLanguageTypeC_plus_plus:
case lldb::eLanguageTypeObjC:
break;
}

std::string transformed_text, size_t &start_loc, size_t &end_loc) {
start_loc = transformed_text.find(m_start_marker);
if (start_loc == std::string::npos)
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,30 @@ class ClangExpressionSourceCode : public ExpressionSourceCode {
static const llvm::StringRef g_prefix_file_name;
static const char *g_expression_prefix;

/// The possible ways an expression can be wrapped.
enum class WrapKind {
/// Wrapped in a non-static member function of a C++ class.
CppMemberFunction,
/// Wrapped in an instance Objective-C method.
ObjCInstanceMethod,
/// Wrapped in a static Objective-C method.
ObjCStaticMethod,
/// Wrapped in a non-member function.
/// Note that this is also used for static member functions of a C++ class.
Function
};

static ClangExpressionSourceCode *CreateWrapped(llvm::StringRef filename,
llvm::StringRef prefix,
llvm::StringRef body) {
llvm::StringRef body,
WrapKind wrap_kind) {
return new ClangExpressionSourceCode(filename, "$__lldb_expr", prefix, body,
Wrap);
Wrap, wrap_kind);
}

/// Generates the source code that will evaluate the expression.
///
/// \param text output parameter containing the source code string.
/// \param wrapping_language If the expression is supossed to be wrapped,
/// then this is the language that should be used for that.
/// \param static_method True iff the expression is valuated inside a static
/// Objective-C method.
/// \param exe_ctx The execution context in which the expression will be
/// evaluated.
/// \param add_locals True iff local variables should be injected into the
Expand All @@ -51,28 +61,32 @@ class ClangExpressionSourceCode : public ExpressionSourceCode {
/// \param modules A list of (C++) modules that the expression should import.
///
/// \return true iff the source code was successfully generated.
bool GetText(std::string &text, lldb::LanguageType wrapping_language,
bool static_method, ExecutionContext &exe_ctx, bool add_locals,
bool GetText(std::string &text, ExecutionContext &exe_ctx, bool add_locals,
bool force_add_all_locals,
llvm::ArrayRef<std::string> modules) const;

// Given a string returned by GetText, find the beginning and end of the body
// passed to CreateWrapped. Return true if the bounds could be found. This
// will also work on text with FixItHints applied.
bool GetOriginalBodyBounds(std::string transformed_text,
lldb::LanguageType wrapping_language,
size_t &start_loc, size_t &end_loc);

protected:
ClangExpressionSourceCode(llvm::StringRef filename, llvm::StringRef name,
llvm::StringRef prefix, llvm::StringRef body,
Wrapping wrap);
Wrapping wrap, WrapKind wrap_kind);

private:
void AddLocalVariableDecls(const lldb::VariableListSP &var_list_sp,
StreamString &stream,
const std::string &expr) const;

/// String marking the start of the user expression.
std::string m_start_marker;
/// String marking the end of the user expression.
std::string m_end_marker;
/// How the expression has been wrapped.
const WrapKind m_wrap_kind;
};

} // namespace lldb_private
Expand Down
Loading

0 comments on commit 8d98476

Please sign in to comment.