hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/debugger
diff options
context:
space:
mode:
Diffstat (limited to 'src/debugger')
-rw-r--r--src/debugger/debugger.cpp39
-rw-r--r--src/debugger/debugger.h2
-rw-r--r--src/debugger/types.h5
3 files changed, 44 insertions, 2 deletions
diff --git a/src/debugger/debugger.cpp b/src/debugger/debugger.cpp
index 7091c57..b7ccfa6 100644
--- a/src/debugger/debugger.cpp
+++ b/src/debugger/debugger.cpp
@@ -534,6 +534,18 @@ namespace Hsdbg
lldb::SBDebugger::Terminate();
}
+ auto Debugger::backend_version() -> std::string
+ {
+ std::string banner = lldb::SBDebugger::GetVersionString();
+ if (const size_t cut = banner.find_first_of("(\n"); cut != std::string::npos)
+ banner.resize(cut);
+ if (banner.starts_with("lldb version "))
+ banner.erase(0, 13);
+ while (!banner.empty() && banner.back() == ' ')
+ banner.pop_back();
+ return banner;
+ }
+
auto Debugger::load_target(const std::filesystem::path& executable) -> Result<void>
{
std::error_code error;
@@ -2054,6 +2066,17 @@ namespace Hsdbg
frame.line = entry.GetLine();
}
+ if (lldb::SBFunction function = source.GetFunction(); function.IsValid())
+ {
+ if (lldb::SBLineEntry first = function.GetStartAddress().GetLineEntry(); first.IsValid())
+ frame.function_first_line = first.GetLine();
+
+ const lldb::addr_t end = function.GetEndAddress().GetLoadAddress(m_session->target);
+ lldb::SBAddress tail = m_session->target.ResolveLoadAddress(end - 1);
+ if (lldb::SBLineEntry last = tail.GetLineEntry(); last.IsValid())
+ frame.function_last_line = std::max(last.GetLine(), frame.line);
+ }
+
m_call_stack.push_back(std::move(frame));
}
}
@@ -2074,13 +2097,25 @@ namespace Hsdbg
return;
lldb::SBValueList variables = frame.GetVariables(true, true, false, true);
+ const std::filesystem::path frame_file = path_of(frame.GetLineEntry().GetFileSpec());
for (uint32_t index = 0; index < variables.GetSize(); ++index)
{
lldb::SBValue value = variables.GetValueAtIndex(index);
- if (value.IsValid())
- m_locals.push_back(to_variable(value, 0));
+ if (!value.IsValid())
+ continue;
+
+ Variable variable = to_variable(value, 0);
+
+ if (lldb::SBDeclaration declaration = value.GetDeclaration();
+ declaration.IsValid() && !frame_file.empty() &&
+ path_of(declaration.GetFileSpec()) == frame_file)
+ {
+ variable.declaration_line = declaration.GetLine();
+ }
+
+ m_locals.push_back(std::move(variable));
}
lldb::SBValueList sets = frame.GetRegisters();
diff --git a/src/debugger/debugger.h b/src/debugger/debugger.h
index d487712..d7885b5 100644
--- a/src/debugger/debugger.h
+++ b/src/debugger/debugger.h
@@ -31,6 +31,8 @@ namespace Hsdbg
auto operator=(const Debugger&) -> Debugger& = delete;
auto operator=(Debugger&&) -> Debugger& = delete;
+ static auto backend_version() -> std::string;
+
auto load_target(const std::filesystem::path& executable) -> Result<void>;
auto unload_target() -> void;
auto launch(const LaunchSpec& spec) -> Result<void>;
diff --git a/src/debugger/types.h b/src/debugger/types.h
index 6f16562..7086384 100644
--- a/src/debugger/types.h
+++ b/src/debugger/types.h
@@ -104,6 +104,9 @@ namespace Hsdbg
std::string function;
std::filesystem::path file;
uint32_t line = 0;
+
+ uint32_t function_first_line = 0;
+ uint32_t function_last_line = 0;
};
struct Thread
@@ -119,6 +122,8 @@ namespace Hsdbg
std::string type;
std::string value;
std::vector<Variable> children;
+
+ uint32_t declaration_line = 0;
};
struct Register