hawkinsw updated this revision to Diff 430781. hawkinsw added a comment. Stupidly missed a few of the places where bare assertions were used.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D124731/new/ https://reviews.llvm.org/D124731 Files: lldb/source/Breakpoint/BreakpointResolverAddress.cpp lldb/source/Commands/Options.td 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
Index: lldb/test/API/commands/breakpoint/set/address-nomodule/inferior.c =================================================================== --- /dev/null +++ lldb/test/API/commands/breakpoint/set/address-nomodule/inferior.c @@ -0,0 +1,6 @@ +int function(int a) { return a; } + +int main() { + int f = function(10); + return f; +} Index: lldb/test/API/commands/breakpoint/set/address-nomodule/TestBreakpointAddressNoModule.py =================================================================== --- /dev/null +++ lldb/test/API/commands/breakpoint/set/address-nomodule/TestBreakpointAddressNoModule.py @@ -0,0 +1,36 @@ +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()) Index: lldb/test/API/commands/breakpoint/set/address-nomodule/Makefile =================================================================== --- /dev/null +++ lldb/test/API/commands/breakpoint/set/address-nomodule/Makefile @@ -0,0 +1,3 @@ +C_SOURCES := inferior.c + +include Makefile.rules Index: lldb/source/Commands/Options.td =================================================================== --- lldb/source/Commands/Options.td +++ lldb/source/Commands/Options.td @@ -128,13 +128,15 @@ 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.">; + "breakpoint, and will get resolved when the module is loaded. If no " + "module is specified, the binary being debugged is considered as a " + "fallback.">; 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 " 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