-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add gdbme flag that starting erigon under gdb (for debug) (#13874)
closes #13586 --------- Co-authored-by: JkLondon <ilya@mikheev.fun>
- Loading branch information
Showing
4 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package gdbme | ||
|
||
import ( | ||
"fmt" | ||
"github.com/erigontech/erigon/cmd/utils" | ||
"os" | ||
"os/exec" | ||
) | ||
|
||
const gdbPath = "/usr/bin/gdb" | ||
|
||
// restartUnderGDB relaunches the current process under GDB for debugging purposes. | ||
func RestartUnderGDB() { | ||
exePath, err := os.Executable() | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, "Error: could not determine executable path:", err) | ||
os.Exit(1) | ||
} | ||
|
||
args := os.Args[1:] | ||
filteredArgs := []string{} | ||
for _, arg := range args { | ||
if arg != "--"+utils.GDBMeFlag.Name { | ||
filteredArgs = append(filteredArgs, arg) | ||
} | ||
} | ||
|
||
gdbArgs := []string{ | ||
"-q", | ||
"-batch", | ||
"-nx", | ||
"-nh", | ||
"-return-child-result", | ||
"-ex", "run", | ||
"-ex", "bt full", | ||
"--args", | ||
exePath, | ||
} | ||
gdbArgs = append(gdbArgs, filteredArgs...) | ||
|
||
fmt.Fprintln(os.Stderr, "Restarting under GDB for crash diagnostics...") | ||
cmd := exec.Command(gdbPath, gdbArgs...) | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
cmd.Stdin = os.Stdin | ||
|
||
err = cmd.Run() | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, "Failed to restart under GDB:", err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters