=?utf-8?q?José?= L. Junior <jljunio...@gmail.com>,
=?utf-8?q?José?= L. Junior <jljunio...@gmail.com>,
=?utf-8?q?José?= L. Junior <jljunio...@gmail.com>
Message-ID:
In-Reply-To: <llvm/llvm-project/pull/67019/l...@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:

The other options would be to ask the Platform.h layer to do this. We have 
platforms classes that abstract things different platforms. Example include 
PlatformLinux, PlatformDarwin (for macOS, watchOS, tvOS, and iOS), 
PlatformAndroid, etc. We could add a default implementation into the 
Platform.h/Platform.cpp file that would set a breakpoint at main. The idea 
would be we would add a virtual function to Platform.h like:
```
class Platform {
  /// Create a beakpoint at the user level starting function for a program.
  virtual BreakpointSP CreateStartBreakpoint(lldb_private::Target &target);
...
```
Then this could can grab the platform from the target and call this:
```
BreakpointSP bp_sp  = target->GetPlatform()->CreateStartBreakpoint();
```
That way new platforms can do the right thing and customize this. The default 
implementation in the Platform.cpp can just do what you did above:
```
BreakpointSP Platform::CreateStartBreakpoint(lldb_private::Target &target) {
  return target_sp->CreateBreakpoint(
        nullptr, nullptr, "main", eFunctionNameTypeAuto, eLanguageTypeUnknown,
        0, eLazyBoolNo, false, false);
```
and we could override this for Darwin (base class for all Apple platforms) to 
use the use my previously suggested code:
```
BreakpointSP PlatformDarwin::CreateStartBreakpoint(lldb_private::Target 
&target) {
  // On Darwin systems the object file's entry point address is the user 
function entry
  // point like "main". Using this kind of breakpoint is more efficient than 
looking up a
  // function by name as this avoids parsing the debug info or symbol tables.
  ModuleSP exe_module_sp = target.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())
    return target.CreateBreakpoint(entry_addr, /*internal=*/false, 
/*hardware=*/false);
  return BreakpointSP();
}
```

https://github.com/llvm/llvm-project/pull/67019
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to