[Lldb-commits] [PATCH] D124731: [lldb] Consider binary as module of last resort

2022-05-01 Thread Will Hawkins via Phabricator via lldb-commits
hawkinsw created this revision.
hawkinsw added reviewers: tatyana-krasnukha, jingham.
Herald added a project: All.
hawkinsw requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

When setting an address breakpoint using a non-section address
in lldb before having ever run the program, the binary itself
is not considered a module. As a result, the breakpoint is
unresolved (and never gets resolved subsequently).

This patch changes that behavior: as a last resort, the binary
is considered as a module when resolving a non-section address
breakpoint.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124731

Files:
  lldb/source/Breakpoint/BreakpointResolverAddress.cpp


Index: lldb/source/Breakpoint/BreakpointResolverAddress.cpp
===
--- lldb/source/Breakpoint/BreakpointResolverAddress.cpp
+++ lldb/source/Breakpoint/BreakpointResolverAddress.cpp
@@ -121,16 +121,27 @@
 
   if (filter.AddressPasses(m_addr)) {
 if (breakpoint.GetNumLocations() == 0) {
-  // If the address is just an offset, and we're given a module, see if we
-  // can find the appropriate module loaded in the binary, and fix up
-  // m_addr to use that.
-  if (!m_addr.IsSectionOffset() && m_module_filespec) {
+  // If the address is just an offset ...
+  if (!m_addr.IsSectionOffset()) {
+ModuleSP containing_module_sp = nullptr;
 Target &target = breakpoint.GetTarget();
-ModuleSpec module_spec(m_module_filespec);
-ModuleSP module_sp = target.GetImages().FindFirstModule(module_spec);
-if (module_sp) {
+if (m_module_filespec) {
+  // ... and we're given a module, see if we can find the
+  // appropriate module loaded in the binary, and fix up
+  // m_addr to use that.
+  ModuleSpec module_spec(m_module_filespec);
+  containing_module_sp =
+  target.GetImages().FindFirstModule(module_spec);
+} else {
+  // ... and we're not given a module, see if the offset is
+  // somewhere in the executable module. If it is, then we'll
+  // fix up m_addr to use that.
+  containing_module_sp = target.GetExecutableModule();
+}
+if (containing_module_sp) {
   Address tmp_address;
-  if (module_sp->ResolveFileAddress(m_addr.GetOffset(), tmp_address))
+  if (containing_module_sp->ResolveFileAddress(m_addr.GetOffset(),
+   tmp_address))
 m_addr = tmp_address;
 }
   }


Index: lldb/source/Breakpoint/BreakpointResolverAddress.cpp
===
--- lldb/source/Breakpoint/BreakpointResolverAddress.cpp
+++ lldb/source/Breakpoint/BreakpointResolverAddress.cpp
@@ -121,16 +121,27 @@
 
   if (filter.AddressPasses(m_addr)) {
 if (breakpoint.GetNumLocations() == 0) {
-  // If the address is just an offset, and we're given a module, see if we
-  // can find the appropriate module loaded in the binary, and fix up
-  // m_addr to use that.
-  if (!m_addr.IsSectionOffset() && m_module_filespec) {
+  // If the address is just an offset ...
+  if (!m_addr.IsSectionOffset()) {
+ModuleSP containing_module_sp = nullptr;
 Target &target = breakpoint.GetTarget();
-ModuleSpec module_spec(m_module_filespec);
-ModuleSP module_sp = target.GetImages().FindFirstModule(module_spec);
-if (module_sp) {
+if (m_module_filespec) {
+  // ... and we're given a module, see if we can find the
+  // appropriate module loaded in the binary, and fix up
+  // m_addr to use that.
+  ModuleSpec module_spec(m_module_filespec);
+  containing_module_sp =
+  target.GetImages().FindFirstModule(module_spec);
+} else {
+  // ... and we're not given a module, see if the offset is
+  // somewhere in the executable module. If it is, then we'll
+  // fix up m_addr to use that.
+  containing_module_sp = target.GetExecutableModule();
+}
+if (containing_module_sp) {
   Address tmp_address;
-  if (module_sp->ResolveFileAddress(m_addr.GetOffset(), tmp_address))
+  if (containing_module_sp->ResolveFileAddress(m_addr.GetOffset(),
+   tmp_address))
 m_addr = tmp_address;
 }
   }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D124731: [lldb] Consider binary as module of last resort

2022-05-01 Thread Will Hawkins via Phabricator via lldb-commits
hawkinsw added a comment.

First, a thank you from a long-time `gdb` user who has finally seen the light 
and working to switch to `lldb`! The work that you all do to build an awesome, 
modern debugger is amazing.

As for this patch, I have committed a few typo fixes in the past, but this is 
my first code submission. I hope that I am following proper procedures and that 
this is a useful improvement.

Please let me know if I have done anything wrong and/or how to make this 
submission better. Thanks again!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124731/new/

https://reviews.llvm.org/D124731

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits