Skip to content

Commit 5672591

Browse files
committed
We need to prepend the module name to the function name used to script LLDB commands.
1 parent 38d1474 commit 5672591

3 files changed

Lines changed: 17 additions & 11 deletions

File tree

src/DebuggerExtensionCommandHandler.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ end
192192
}
193193

194194
static void lldb_macro_binding(ostream& def_stream, ostream& call_stream,
195+
const string* module_name,
195196
const DebuggerExtensionCommand& cmd) {
196197
string func_name = "rr_command_";
197198
for (char ch : cmd.name()) {
@@ -214,12 +215,15 @@ static void lldb_macro_binding(ostream& def_stream, ostream& call_stream,
214215
def_stream << "\n"
215216
<< " command_impl(debugger, command, exe_ctx, result, cmd_name, auto_args)\n"
216217
<< "\n";
217-
call_stream << " debugger.HandleCommand('command script add -f " << func_name
218-
<< " " << cmd.name() << "')\n";
218+
call_stream << " debugger.HandleCommand('command script add -f ";
219+
if (module_name) {
220+
call_stream << *module_name << ".";
221+
}
222+
call_stream << func_name << " " << cmd.name() << "')\n";
219223
}
220224

221225
DebuggerExtensionCommandHandler::LldbCommands
222-
DebuggerExtensionCommandHandler::lldb_python_macros() {
226+
DebuggerExtensionCommandHandler::lldb_python_macros(const string* module_name) {
223227
DebuggerExtensionCommand::init_auto_args();
224228
stringstream ss;
225229
ss << R"Delimiter(import lldb
@@ -259,7 +263,7 @@ def command_impl(debugger, command, exe_ctx, result, cmd_name, auto_args):
259263
stringstream call_stream;
260264
if (debugger_command_list) {
261265
for (auto& it : *debugger_command_list) {
262-
lldb_macro_binding(ss, call_stream, *it);
266+
lldb_macro_binding(ss, call_stream, module_name, *it);
263267
}
264268
}
265269
LldbCommands cmds;

src/DebuggerExtensionCommandHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DebuggerExtensionCommandHandler {
3030
// 2-space-indented code to run on startup.
3131
std::string run_on_startup;
3232
};
33-
static LldbCommands lldb_python_macros();
33+
static LldbCommands lldb_python_macros(const string* module_name);
3434

3535
static void register_command(DebuggerExtensionCommand& cmd);
3636

src/launch_debugger.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,13 @@ static string gdb_rr_macros(const string* file_to_delete) {
120120
return ss.str();
121121
}
122122

123-
static const string& lldb_python_rr_macros(const string* file_to_delete) {
123+
static const string& lldb_python_rr_macros(
124+
const string* file_to_delete, const string* module_name) {
124125
static string s;
125126

126127
if (s.empty()) {
127-
auto cmds = DebuggerExtensionCommandHandler::lldb_python_macros();
128+
auto cmds = DebuggerExtensionCommandHandler::lldb_python_macros(
129+
module_name);
128130
stringstream ss;
129131
ss << cmds.toplevel_definitions
130132
<< "import os\n"
@@ -316,11 +318,11 @@ void launch_debugger(ScopedFd& params_pipe_fd,
316318
RENAME_NOREPLACE)) {
317319
FATAL() << "Can't fix temp file name";
318320
}
319-
file.name = new_name;
320-
string script = lldb_python_rr_macros(&file.name);
321+
string module_name(basename(file.name.c_str()));
322+
string script = lldb_python_rr_macros(&new_name, &module_name);
321323
write_all(file.fd, script.data(), script.size());
322324
cmd.push_back("-o");
323-
cmd.push_back("command script import " + file.name);
325+
cmd.push_back("command script import " + new_name);
324326
env.push_back("LLDB_UNDER_RR=1");
325327
break;
326328
}
@@ -392,6 +394,6 @@ void emergency_debug(Task* t) {
392394

393395
string gdb_init_script() { return gdb_rr_macros(nullptr); }
394396

395-
string lldb_init_script() { return lldb_python_rr_macros(nullptr); }
397+
string lldb_init_script() { return lldb_python_rr_macros(nullptr, nullptr); }
396398

397399
} // namespace rr

0 commit comments

Comments
 (0)