commit ce4f018e5629cf978120951226a8a7d61eb8a3ed
parent 631f2c12000fee47b68e2b477d18eef0a593af04
Author: Remy Noulin <loader2x@gmail.com>
Date: Wed, 15 Jul 2020 21:51:54 +0200
add -g, -gt, -gm and -ga options in sheepy to debug executables
this launches gdb or any debugger specified in ~/.sheepy/config.yml
debuggerCmd string directly.
It avoids running sheepy -c prog.c and then starting the debugger
src/common.h | 4 +++
src/sheepy.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++----------
src/sheepy.h | 1 +
3 files changed, 74 insertions(+), 13 deletions(-)
Diffstat:
3 files changed, 74 insertions(+), 13 deletions(-)
diff --git a/src/common.h b/src/common.h
@@ -58,6 +58,7 @@
" asanCflags: -fsanitize=address -fno-omit-frame-pointer -fsanitize-recover=address # these flags are overriden by package.yml\n"\
" asanLflags: -rdynamic -fsanitize=address -lasan # these flags are overriden by package.yml\n"\
" asanLinkWithGold: true\n"\
+ " debuggerCmd: gdb -tui --args\n"\
" key: uninitialized"
#define CONFIG_YML_NO_GOLD "---\n"\
@@ -88,6 +89,7 @@
" asanCflags: -fsanitize=address -fno-omit-frame-pointer -fsanitize-recover=address # these flags are overriden by package.yml\n"\
" asanLflags: -rdynamic -fsanitize=address -lasan # these flags are overriden by package.yml\n"\
" asanLinkWithGold: false\n"\
+ " debuggerCmd: gdb -tui --args\n"\
" key: uninitialized"
#define CONFIG_YML_NO_GOLD_ARM "---\n"\
@@ -118,6 +120,7 @@
" asanCflags: -fsanitize=address -fno-omit-frame-pointer -fsanitize-recover=address # these flags are overriden by package.yml\n"\
" asanLflags: -rdynamic -fsanitize=address -lasan # these flags are overriden by package.yml\n"\
" asanLinkWithGold: false\n"\
+ " debuggerCmd: gdb -tui --args\n"\
" key: uninitialized"
#define CONFIG_YML_HAIKU "---\n"\
@@ -148,6 +151,7 @@
" asanCflags: -fsanitize=address -fno-omit-frame-pointer -fsanitize-recover=address # these flags are overriden by package.yml\n"\
" asanLflags: -rdynamic -fsanitize=address -lasan # these flags are overriden by package.yml\n"\
" asanLinkWithGold: false\n"\
+ " debuggerCmd: gdb -tui --args\n"\
" key: uninitialized"
extern char *defaultSpC;
diff --git a/src/sheepy.c b/src/sheepy.c
@@ -186,6 +186,7 @@ int MAIN(int ARGC, char** ARGV) {
sheepyParams.removeBuild = 0;
sheepyParams.parallel = 1;
sheepyParams.genTest = 0;
+ sheepyParams.debugExe = 0;
// parallel has to be defined and 0 to disable parallel compilation
if (hasG(cfgD, "parallelSheepy") && !getG(cfgD, rtI32, "parallelSheepy")) {
@@ -291,19 +292,23 @@ int MAIN(int ARGC, char** ARGV) {
putsG(" NO ARGUMENT Compile bin executable or compile library from package.yml");
putsG(" PROGNAME.c No option: compile and run executable");
put
- putsG(" -c (PROGNAME.c) Compile executable in argument or bin from package");
- putsG(" -e (PROGNAME.c) Show executable path for argument or bin from package"); {
- putsG(" -l (PROGNAME.c) Compile static and dynamic libraries for argument or bin from package"); {
- putsG(" -d (PROGNAME.c) Delete intermediary files for argument or bin from package"); {
- putsG(" -t (PROGNAME.c) Compile executable in argument or testBin from package using the test compiler and test linker flags");
- putsG(" -m (PROGNAME.c) Compile executable in argument or memcheckBin from package using the memcheck compiler and linker flags");
- putsG(" -a (PROGNAME.c) Compile executable in argument or asanBin from package using the asan compiler and linker flags");
- putsG(" -n PROGNAME New source program from template");
- putsG(" -r Remove all temporary build files in ~/.sheepy/build");
- putsG(" -C CLASSNAME Generate C templates for classname (classnames start with lowercase letters, the first char in classname is lowered)"); {
- putsG(" -T Generate C unit test templates (using the libcheck test library), the generated filename is set with testBin in "PACKAGE);
- putsG(" -D Show default " HOME_DIR CONFIG_NAME " configuration");
- putsG(" -h Show this help text");
+ putsG(" -c (PROGNAME.c) Compile executable in argument or bin from package");
+ putsG(" -e (PROGNAME.c) Show executable path for argument or bin from package"); {
+ putsG(" -l (PROGNAME.c) Compile static and dynamic libraries for argument or bin from package"); {
+ putsG(" -d (PROGNAME.c) Delete intermediary files for argument or bin from package"); {
+ putsG(" -t (PROGNAME.c) Compile executable in argument or testBin from package using the test compiler and test linker flags");
+ putsG(" -m (PROGNAME.c) Compile executable in argument or memcheckBin from package using the memcheck compiler and linker flags");
+ putsG(" -a (PROGNAME.c) Compile executable in argument or asanBin from package using the asan compiler and linker flags");
+ putsG(" -n PROGNAME New source program from template");
+ putsG(" -r Remove all temporary build files in ~/.sheepy/build");
+ putsG(" -C CLASSNAME Generate C templates for classname (classnames start with lowercase letters, the first char in classname is lowered)"); {
+ putsG(" -T Generate C unit test templates (using the libcheck test library), the generated filename is set with testBin in "PACKAGE);
+ putsG(" -g (PROGNAME.c) Debug already compiled executable with debuggerCmd in config.yml");
+ putsG(" -gt (PROGNAME.c) Debug already compiled testBin executable from package with debuggerCmd in config.yml");
+ putsG(" -gm (PROGNAME.c) Debug already compiled memcheckBin executable from package with debuggerCmd in config.yml");
+ putsG(" -ga (PROGNAME.c) Debug already compiled asanBin executable from package with debuggerCmd in config.yml");
+ putsG(" -D Show default " HOME_DIR CONFIG_NAME " configuration");
+ putsG(" -h Show this help text");
XSUCCESS
}
}
@@ -338,6 +343,7 @@ int MAIN(int ARGC, char** ARGV) {
dum = bin ? ssGet(bin) : argv[2];
}
else if (eqG(argv[1], "-t")) {
+ testOption:
sheepyParams.test = 1;
if (bin) {
terminateG(bin);
@@ -352,6 +358,7 @@ int MAIN(int ARGC, char** ARGV) {
}
}
else if (eqG(argv[1], "-m")) {
+ memcheckOption:
sheepyParams.memcheck = 1;
sheepyParams.libsheepyMemcheck = 1;
// check if libsheepyMemcheck exists
@@ -378,6 +385,7 @@ int MAIN(int ARGC, char** ARGV) {
}
}
else if (eqG(argv[1], "-a")) {
+ asanOption:
sheepyParams.asan = 1;
sheepyParams.libsheepyAsan = 1;
// check if libsheepyMemAsan exists
@@ -419,6 +427,22 @@ int MAIN(int ARGC, char** ARGV) {
sheepyParams.genTest = 1;
dum = argv[1];
}
+ else if (eqG(argv[1], "-g")) {
+ sheepyParams.debugExe = 1;
+ dum = bin ? ssGet(bin) : argv[2];
+ }
+ else if (eqG(argv[1], "-gt")) {
+ sheepyParams.debugExe = 1;
+ goto testOption;
+ }
+ else if (eqG(argv[1], "-gm")) {
+ sheepyParams.debugExe = 1;
+ goto memcheckOption;
+ }
+ else if (eqG(argv[1], "-ga")) {
+ sheepyParams.debugExe = 1;
+ goto asanOption;
+ }
else {
dum = argv[1];
}
@@ -781,6 +805,38 @@ int MAIN(int ARGC, char** ARGV) {
char *buildExePath = catS(buildPath, "/", rootMain);
//logVarG(buildPath);
+
+
+ if (sheepyParams.debugExe) {
+ char *debuggerCmd = getG(cfgJ, rtChar, "debuggerCmd");;
+ if (!debuggerCmd) {
+ printf(BLD RED"debuggerCmd not found in "HOME_DIR CONFIG_NAME ", run 'sheepy -D' to see an example." RST);
+ XFailure;
+ }
+ if (!fileExists(buildExePath)) {
+ printf(BLD RED"Executable not found, run the compile command first. Path was: %s"RST, buildExePath);
+ XFailure;
+ }
+
+ createAllocateSmallArray(paramL);
+ // debug program with parameters on command line
+ rangeFrom(i, 3, argc)
+ pushG(paramL, argv[i]);
+ // create parameter string
+ char *params = joinSG(paramL, " ");
+ if (!params) {
+ emptyS(params);
+ }
+
+ char *debugCommand = formatS("%s %s %s", debuggerCmd, buildExePath, params);;
+ system(debugCommand);
+ if (getG(cfgD, rtBool, "print_compile_commands")) {
+ printf("%s\n", debugCommand);
+ }
+ XSuccess;
+ }
+
+
if (sheepyParams.showExe) {
printf("The executable path is: " GRN "%s" RST
"\nThe executable directory is: " GRN "%s" RST, buildExePath, shDirname(buildExePath));
diff --git a/src/sheepy.h b/src/sheepy.h
@@ -36,6 +36,7 @@ struct {
int parallel;
int cclass;
int genTest;
+ int debugExe;
} sheepyParams;
// MacOS definition