[Lldb-commits] [lldb] [lldb] add command start (PR #67019)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 22 16:47:02 PDT 2023


=?utf-8?q?José?= L. Junior <jljuniorpb at gmail.com>
Message-ID:
In-Reply-To: <llvm/llvm-project/pull/67019/lldb at github.com>


================
@@ -38,7 +38,18 @@ Status CommandOptionsProcessLaunch::SetOptionValue(
   case 's': // Stop at program entry point
     launch_info.GetFlags().Set(eLaunchFlagStopAtEntry);
     break;
-
+  case 'm': // Stop at main function
+  {
+    TargetSP target_sp =
+        execution_context ? execution_context->GetTargetSP() : TargetSP();
+    BreakpointSP bp_sp = target_sp->CreateBreakpoint(
+        nullptr, nullptr, "main", eFunctionNameTypeAuto, eLanguageTypeUnknown,
----------------
clayborg wrote:

eFunctionNameTypeAuto is too broad and might not work for all languages. Most executable object files have an accessor to fetch the entry point address, which is the address of the main function. The "--stop-at-entry" is for stopping right away at the first instruction of the program, not the main function, so even though the API used below mentions the entry point, it is actually the main function.
```
ModuleSP exe_module_sp = target_sp->GetExecutableModule();
lldb_private::Address entry_addr;
if (exe_module_sp ) {
  ObjectFile *objfile = exe_module_sp ->GetObjectFile();
  if (objfile)
      entry_addr = objfile->GetEntryPointAddress();
}
if (entry_addr.IsValid()) {
  BreakpointSP bp_sp = target_sp->CreateBreakpoint(entry_addr, /*internal=*/false, /*hardware=*/false);
  if (!bp_sp)
    error.SetErrorString("entry breakpoint creation failed.");
} else {
  error.SetErrorString("executable doesn't have an entrypoint address.");
}
```

https://github.com/llvm/llvm-project/pull/67019


More information about the lldb-commits mailing list