mib created this revision.
mib added reviewers: JDevlieghere, labath.
mib added a project: LLDB.
Herald added a subscriber: lldb-commits.
This patch changes the way the StackFrame Recognizers match a certain
frame.
Until now, recognizers could be registered with a function
name but also an alternate symbol.
This change is motivated by a test failure for the Assert frame
recognizer on Linux. Depending the version of the libc, the abort
function (triggered by an assertion), could have more than two
signatures (i.e. `raise`, `__GI_raise` and `gsignal`).
Instead of only checking the default symbol name and the alternate one,
lldb will iterate over a list of symbols to match against.
rdar://60386577
Signed-off-by: Med Ismail Bennani <[email protected]>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D76188
Files:
lldb/include/lldb/Target/StackFrameRecognizer.h
lldb/source/Commands/CommandObjectFrame.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
lldb/source/Target/AssertFrameRecognizer.cpp
lldb/source/Target/StackFrameRecognizer.cpp
lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py
lldb/unittests/Target/StackFrameRecognizerTest.cpp
Index: lldb/unittests/Target/StackFrameRecognizerTest.cpp
===================================================================
--- lldb/unittests/Target/StackFrameRecognizerTest.cpp
+++ lldb/unittests/Target/StackFrameRecognizerTest.cpp
@@ -76,8 +76,7 @@
bool any_printed = false;
StackFrameRecognizerManager::ForEach(
[&any_printed](uint32_t recognizer_id, std::string name,
- std::string function, std::string symbol,
- std::string alternate_symbol,
+ std::string function, std::vector<ConstString> &symbols,
bool regexp) { any_printed = true; });
EXPECT_TRUE(any_printed);
Index: lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py
===================================================================
--- lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py
+++ lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py
@@ -33,21 +33,21 @@
self.runCmd("frame recognizer add -l recognizer.MyFrameRecognizer -s a.out -n foo")
self.expect("frame recognizer list",
- substrs=['0: recognizer.MyFrameRecognizer, module a.out, function foo'])
+ substrs=['0: recognizer.MyFrameRecognizer, module a.out, symbol foo'])
self.runCmd("frame recognizer add -l recognizer.MyOtherFrameRecognizer -s a.out -n bar -x")
self.expect(
"frame recognizer list",
substrs=[
- '1: recognizer.MyOtherFrameRecognizer, module a.out, function bar (regexp)',
- '0: recognizer.MyFrameRecognizer, module a.out, function foo'
+ '1: recognizer.MyOtherFrameRecognizer, module a.out, symbol bar (regexp)',
+ '0: recognizer.MyFrameRecognizer, module a.out, symbol foo'
])
self.runCmd("frame recognizer delete 0")
self.expect("frame recognizer list",
- substrs=['1: recognizer.MyOtherFrameRecognizer, module a.out, function bar (regexp)'])
+ substrs=['1: recognizer.MyOtherFrameRecognizer, module a.out, symbol bar (regexp)'])
self.runCmd("frame recognizer clear")
Index: lldb/source/Target/StackFrameRecognizer.cpp
===================================================================
--- lldb/source/Target/StackFrameRecognizer.cpp
+++ lldb/source/Target/StackFrameRecognizer.cpp
@@ -51,27 +51,31 @@
class StackFrameRecognizerManagerImpl {
public:
void AddRecognizer(StackFrameRecognizerSP recognizer, ConstString module,
- ConstString symbol, ConstString alternate_symbol,
+ std::vector<ConstString> symbols,
bool first_instruction_only) {
m_recognizers.push_front({(uint32_t)m_recognizers.size(), false, recognizer,
- false, module, RegularExpressionSP(), symbol,
- alternate_symbol, RegularExpressionSP(),
- first_instruction_only});
+ false, module, RegularExpressionSP(), symbols,
+ RegularExpressionSP(), first_instruction_only});
}
void AddRecognizer(StackFrameRecognizerSP recognizer,
RegularExpressionSP module, RegularExpressionSP symbol,
bool first_instruction_only) {
- m_recognizers.push_front({(uint32_t)m_recognizers.size(), false, recognizer,
- true, ConstString(), module, ConstString(),
- ConstString(), symbol, first_instruction_only});
+ m_recognizers.push_front({(uint32_t)m_recognizers.size(),
+ false,
+ recognizer,
+ true,
+ ConstString(),
+ module,
+ {},
+ symbol,
+ first_instruction_only});
}
void ForEach(
std::function<void(uint32_t recognized_id, std::string recognizer_name,
- std::string module, std::string symbol,
- std::string alternate_symbol, bool regexp)> const
- &callback) {
+ std::string module, std::vector<ConstString> &symbols,
+ bool regexp)> const &callback) {
for (auto entry : m_recognizers) {
if (entry.is_regexp) {
std::string module_name;
@@ -82,17 +86,15 @@
if (entry.symbol_regexp)
symbol_name = entry.symbol_regexp->GetText().str();
+ entry.symbols.clear();
+ entry.symbols.push_back(ConstString(symbol_name));
+
callback(entry.recognizer_id, entry.recognizer->GetName(), module_name,
- symbol_name, {}, true);
+ entry.symbols, true);
} else {
- std::string alternate_symbol;
- if (!entry.alternate_symbol.IsEmpty())
- alternate_symbol.append(entry.alternate_symbol.GetCString());
-
callback(entry.recognizer_id, entry.recognizer->GetName(),
- entry.module.GetCString(), entry.symbol.GetCString(),
- alternate_symbol, false);
+ entry.module.GetCString(), entry.symbols, false);
}
}
}
@@ -128,10 +130,9 @@
if (entry.module_regexp)
if (!entry.module_regexp->Execute(module_name.GetStringRef())) continue;
- if (entry.symbol)
- if (entry.symbol != function_name &&
- (!entry.alternate_symbol ||
- entry.alternate_symbol != function_name))
+ if (!entry.symbols.empty())
+ if (std::find(entry.symbols.begin(), entry.symbols.end(),
+ function_name) == entry.symbols.end())
continue;
if (entry.symbol_regexp)
@@ -160,8 +161,7 @@
bool is_regexp;
ConstString module;
RegularExpressionSP module_regexp;
- ConstString symbol;
- ConstString alternate_symbol;
+ std::vector<ConstString> symbols;
RegularExpressionSP symbol_regexp;
bool first_instruction_only;
};
@@ -176,10 +176,10 @@
}
void StackFrameRecognizerManager::AddRecognizer(
- StackFrameRecognizerSP recognizer, ConstString module, ConstString symbol,
- ConstString alternate_symbol, bool first_instruction_only) {
+ StackFrameRecognizerSP recognizer, ConstString module,
+ std::vector<ConstString> symbols, bool first_instruction_only) {
GetStackFrameRecognizerManagerImpl().AddRecognizer(
- recognizer, module, symbol, alternate_symbol, first_instruction_only);
+ recognizer, module, symbols, first_instruction_only);
}
void StackFrameRecognizerManager::AddRecognizer(
@@ -191,9 +191,8 @@
void StackFrameRecognizerManager::ForEach(
std::function<void(uint32_t recognized_id, std::string recognizer_name,
- std::string module, std::string symbol,
- std::string alternate_symbol, bool regexp)> const
- &callback) {
+ std::string module, std::vector<ConstString> &symbols,
+ bool regexp)> const &callback) {
GetStackFrameRecognizerManagerImpl().ForEach(callback);
}
Index: lldb/source/Target/AssertFrameRecognizer.cpp
===================================================================
--- lldb/source/Target/AssertFrameRecognizer.cpp
+++ lldb/source/Target/AssertFrameRecognizer.cpp
@@ -21,8 +21,11 @@
/// name.
struct SymbolLocation {
FileSpec module_spec;
- ConstString symbol_name;
- ConstString alternate_symbol_name;
+ std::vector<ConstString> symbols;
+
+ bool HasSymbol(ConstString symbol) {
+ return std::find(symbols.begin(), symbols.end(), symbol) != symbols.end();
+ }
};
/// Fetches the abort frame location depending on the current platform.
@@ -39,12 +42,13 @@
case llvm::Triple::Darwin:
case llvm::Triple::MacOSX:
location.module_spec = FileSpec("libsystem_kernel.dylib");
- location.symbol_name.SetString("__pthread_kill");
+ location.symbols.push_back(ConstString("__pthread_kill"));
break;
case llvm::Triple::Linux:
location.module_spec = FileSpec("libc.so.6");
- location.symbol_name.SetString("raise");
- location.alternate_symbol_name.SetString("__GI_raise");
+ location.symbols.push_back(ConstString("raise"));
+ location.symbols.push_back(ConstString("__GI_raise"));
+ location.symbols.push_back(ConstString("gsignal"));
break;
default:
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_UNWIND));
@@ -69,12 +73,12 @@
case llvm::Triple::Darwin:
case llvm::Triple::MacOSX:
location.module_spec = FileSpec("libsystem_c.dylib");
- location.symbol_name.SetString("__assert_rtn");
+ location.symbols.push_back(ConstString("__assert_rtn"));
break;
case llvm::Triple::Linux:
location.module_spec = FileSpec("libc.so.6");
- location.symbol_name.SetString("__assert_fail");
- location.alternate_symbol_name.SetString("__GI___assert_fail");
+ location.symbols.push_back(ConstString("__assert_fail"));
+ location.symbols.push_back(ConstString("__GI___assert_fail"));
break;
default:
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_UNWIND));
@@ -97,8 +101,7 @@
StackFrameRecognizerManager::AddRecognizer(
StackFrameRecognizerSP(new AssertFrameRecognizer()),
- location.module_spec.GetFilename(), ConstString(location.symbol_name),
- ConstString(location.alternate_symbol_name),
+ location.module_spec.GetFilename(), location.symbols,
/*first_instruction_only*/ false);
});
}
@@ -139,10 +142,7 @@
ConstString func_name = sym_ctx.GetFunctionName();
- if (func_name == location.symbol_name ||
- (!location.alternate_symbol_name.IsEmpty() &&
- func_name == location.alternate_symbol_name)) {
-
+ if (location.HasSymbol(func_name)) {
// We go a frame beyond the assert location because the most relevant
// frame for the user is the one in which the assert function was called.
// If the assert location is the last frame fetched, then it is set as
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===================================================================
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -2690,9 +2690,10 @@
FileSpec module;
ConstString function;
std::tie(module, function) = AppleObjCRuntime::GetExceptionThrowLocation();
+ std::vector<ConstString> symbols = {function};
StackFrameRecognizerManager::AddRecognizer(
StackFrameRecognizerSP(new ObjCExceptionThrowFrameRecognizer()),
- module.GetFilename(), function, /*alternate_symbol*/ {},
+ module.GetFilename(), symbols,
/*first_instruction_only*/ true);
});
}
Index: lldb/source/Commands/CommandObjectFrame.cpp
===================================================================
--- lldb/source/Commands/CommandObjectFrame.cpp
+++ lldb/source/Commands/CommandObjectFrame.cpp
@@ -746,7 +746,7 @@
m_module = std::string(option_arg);
break;
case 'n':
- m_function = std::string(option_arg);
+ m_symbols.push_back(std::string(option_arg));
break;
case 'x':
m_regex = true;
@@ -760,7 +760,7 @@
void OptionParsingStarting(ExecutionContext *execution_context) override {
m_module = "";
- m_function = "";
+ m_symbols.clear();
m_class_name = "";
m_regex = false;
}
@@ -772,7 +772,7 @@
// Instance variables to hold the values for command options.
std::string m_class_name;
std::string m_module;
- std::string m_function;
+ std::vector<std::string> m_symbols;
bool m_regex;
};
@@ -854,9 +854,10 @@
return false;
}
- if (m_options.m_function.empty()) {
- result.AppendErrorWithFormat("%s needs a function name (-n argument).\n",
- m_cmd_name.c_str());
+ if (m_options.m_symbols.empty()) {
+ result.AppendErrorWithFormat(
+ "%s needs at lease one symbol name (-n argument).\n",
+ m_cmd_name.c_str());
result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -876,12 +877,13 @@
auto module =
RegularExpressionSP(new RegularExpression(m_options.m_module));
auto func =
- RegularExpressionSP(new RegularExpression(m_options.m_function));
+ RegularExpressionSP(new RegularExpression(m_options.m_symbols.front()));
StackFrameRecognizerManager::AddRecognizer(recognizer_sp, module, func);
} else {
auto module = ConstString(m_options.m_module);
- auto func = ConstString(m_options.m_function);
- StackFrameRecognizerManager::AddRecognizer(recognizer_sp, module, func, {});
+ std::vector<ConstString> symbols(m_options.m_symbols.begin(),
+ m_options.m_symbols.end());
+ StackFrameRecognizerManager::AddRecognizer(recognizer_sp, module, symbols);
}
#endif
@@ -958,9 +960,9 @@
bool DoExecute(Args &command, CommandReturnObject &result) override {
bool any_printed = false;
StackFrameRecognizerManager::ForEach(
- [&result, &any_printed](uint32_t recognizer_id, std::string name,
- std::string module, std::string symbol,
- std::string alternate_symbol, bool regexp) {
+ [&result, &any_printed](
+ uint32_t recognizer_id, std::string name, std::string module,
+ std::vector<ConstString> &symbols, bool regexp) {
Stream &stream = result.GetOutputStream();
if (name.empty())
@@ -969,10 +971,9 @@
stream << std::to_string(recognizer_id) << ": " << name;
if (!module.empty())
stream << ", module " << module;
- if (!symbol.empty())
- stream << ", function " << symbol;
- if (!alternate_symbol.empty())
- stream << ", symbol " << alternate_symbol;
+ if (!symbols.empty())
+ for (auto &symbol : symbols)
+ stream << ", symbol " << symbol;
if (regexp)
stream << " (regexp)";
Index: lldb/include/lldb/Target/StackFrameRecognizer.h
===================================================================
--- lldb/include/lldb/Target/StackFrameRecognizer.h
+++ lldb/include/lldb/Target/StackFrameRecognizer.h
@@ -101,8 +101,8 @@
class StackFrameRecognizerManager {
public:
static void AddRecognizer(lldb::StackFrameRecognizerSP recognizer,
- ConstString module, ConstString symbol,
- ConstString alternate_symbol,
+ ConstString module,
+ std::vector<ConstString> symbols,
bool first_instruction_only = true);
static void AddRecognizer(lldb::StackFrameRecognizerSP recognizer,
@@ -112,9 +112,8 @@
static void ForEach(
std::function<void(uint32_t recognizer_id, std::string recognizer_name,
- std::string module, std::string symbol,
- std::string alternate_symbol, bool regexp)> const
- &callback);
+ std::string module, std::vector<ConstString> &symbols,
+ bool regexp)> const &callback);
static bool RemoveRecognizerWithID(uint32_t recognizer_id);
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits