[Lldb-commits] [lldb] b876c23 - Revert "[lldb] Consider binary as module of last resort"

Muhammad Omair Javaid via lldb-commits lldb-commits at lists.llvm.org
Sun May 22 23:20:05 PDT 2022


Author: Muhammad Omair Javaid
Date: 2022-05-23T11:19:48+05:00
New Revision: b876c23604c748bd267c1fcb0572845ee61549cc

URL: https://github.com/llvm/llvm-project/commit/b876c23604c748bd267c1fcb0572845ee61549cc
DIFF: https://github.com/llvm/llvm-project/commit/b876c23604c748bd267c1fcb0572845ee61549cc.diff

LOG: Revert "[lldb] Consider binary as module of last resort"

This reverts commit a3c3482ceb529206b0ae4e7782e5496da5e0879d.
It broke LLDB API test TestBadAddressBreakpoints.py

Differential revision: https://reviews.llvm.org/D124731

Added: 
    

Modified: 
    lldb/source/Breakpoint/BreakpointResolverAddress.cpp
    lldb/source/Commands/Options.td

Removed: 
    lldb/test/API/commands/breakpoint/set/address-nomodule/Makefile
    lldb/test/API/commands/breakpoint/set/address-nomodule/TestBreakpointAddressNoModule.py
    lldb/test/API/commands/breakpoint/set/address-nomodule/inferior.c


################################################################################
diff  --git a/lldb/source/Breakpoint/BreakpointResolverAddress.cpp b/lldb/source/Breakpoint/BreakpointResolverAddress.cpp
index 9b6b6d29cbce8..c173fc0c2a7a6 100644
--- a/lldb/source/Breakpoint/BreakpointResolverAddress.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolverAddress.cpp
@@ -121,27 +121,16 @@ Searcher::CallbackReturn BreakpointResolverAddress::SearchCallback(
 
   if (filter.AddressPasses(m_addr)) {
     if (breakpoint.GetNumLocations() == 0) {
-      // If the address is just an offset ...
-      if (!m_addr.IsSectionOffset()) {
-        ModuleSP containing_module_sp = nullptr;
+      // 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) {
         Target &target = breakpoint.GetTarget();
-        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) {
+        ModuleSpec module_spec(m_module_filespec);
+        ModuleSP module_sp = target.GetImages().FindFirstModule(module_spec);
+        if (module_sp) {
           Address tmp_address;
-          if (containing_module_sp->ResolveFileAddress(m_addr.GetOffset(),
-                                                       tmp_address))
+          if (module_sp->ResolveFileAddress(m_addr.GetOffset(), tmp_address))
             m_addr = tmp_address;
         }
       }

diff  --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index 284437887a0b9..c326f8a320748 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -128,15 +128,13 @@ let Command = "breakpoint set" in {
     Arg<"AddressOrExpression">, Required,
     Desc<"Set the breakpoint at the specified address.  If the address maps "
     "uniquely to a particular binary, then the address will be converted to "
-    "a \"file\" address, so that the breakpoint will track that binary+offset "
+    "a \"file\"address, so that the breakpoint will track that binary+offset "
     "no matter where the binary eventually loads.  Alternately, if you also "
     "specify the module - with the -s option - then the address will be "
     "treated as a file address in that module, and resolved accordingly.  "
     "Again, this will allow lldb to track that offset on subsequent reloads.  "
     "The module need not have been loaded at the time you specify this "
-    "breakpoint, and will get resolved when the module is loaded.  If no "
-    "module is specified, the binary being debugged is considered as a "
-    "fallback.">;
+    "breakpoint, and will get resolved when the module is loaded.">;
   def breakpoint_set_name : Option<"name", "n">, Group<3>, Arg<"FunctionName">,
     Completion<"Symbol">, Required,
     Desc<"Set the breakpoint by function name.  Can be repeated multiple times "

diff  --git a/lldb/test/API/commands/breakpoint/set/address-nomodule/Makefile b/lldb/test/API/commands/breakpoint/set/address-nomodule/Makefile
deleted file mode 100644
index 7c82a2dde6c2e..0000000000000
--- a/lldb/test/API/commands/breakpoint/set/address-nomodule/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
-C_SOURCES := inferior.c
-
-include Makefile.rules

diff  --git a/lldb/test/API/commands/breakpoint/set/address-nomodule/TestBreakpointAddressNoModule.py b/lldb/test/API/commands/breakpoint/set/address-nomodule/TestBreakpointAddressNoModule.py
deleted file mode 100644
index 3e3550d694708..0000000000000
--- a/lldb/test/API/commands/breakpoint/set/address-nomodule/TestBreakpointAddressNoModule.py
+++ /dev/null
@@ -1,36 +0,0 @@
-import lldb
-from lldbsuite.test.decorators import *
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test import lldbutil
-
-class TestCase(TestBase):
-
-    mydir = TestBase.compute_mydir(__file__)
-
-    def get_address_from_symbol(self, symbol):
-        target = lldbutil.run_to_breakpoint_make_target(self, "a.out", True)
-        bp = target.BreakpointCreateByName(symbol, None)
-        address = bp.GetLocationAtIndex(0).GetAddress().GetFileAddress()
-        return address
-
-    def test_set_address_no_module(self):
-        self.build()
-
-        main_address = self.get_address_from_symbol("main")
-
-        target = lldbutil.run_to_breakpoint_make_target(self)
-        debugger = target.GetDebugger()
-
-        debugger.HandleCommand(f"break set -a {main_address:#x}")
-        self.assertEquals(target.GetNumBreakpoints(), 1)
-
-        bp = target.GetBreakpointAtIndex(0)
-        self.assertIsNotNone(bp)
-
-        _, _, thread, _ = lldbutil.run_to_breakpoint_do_run(self, target, bp)
-        self.assertGreaterEqual(thread.GetNumFrames(), 1)
-
-        thread_pc = thread.GetFrameAtIndex(0).GetPCAddress()
-        self.assertNotEqual(thread_pc, None)
-
-        self.assertEquals(main_address, thread_pc.GetFileAddress())

diff  --git a/lldb/test/API/commands/breakpoint/set/address-nomodule/inferior.c b/lldb/test/API/commands/breakpoint/set/address-nomodule/inferior.c
deleted file mode 100644
index b3af1438927c1..0000000000000
--- a/lldb/test/API/commands/breakpoint/set/address-nomodule/inferior.c
+++ /dev/null
@@ -1,6 +0,0 @@
-int function(int a) { return a; }
-
-int main() {
-  int f = function(10);
-  return f;
-}


        


More information about the lldb-commits mailing list