Remove debugger program arguments limit in -22LOC

This commit is contained in:
pancake 2013-07-03 16:09:50 +02:00
parent 7cb31941a6
commit 63c57a1c99
1 changed files with 10 additions and 32 deletions

View File

@ -173,7 +173,7 @@ int main(int argc, char **argv) {
int fullfile = 0; int fullfile = 0;
ut32 bsize = 0; ut32 bsize = 0;
ut64 seek = 0; ut64 seek = 0;
char *pfile = NULL, file[4096]; char *pfile = NULL, *file = NULL;
char *cmdfile[32]; char *cmdfile[32];
const char *debugbackend = "native"; const char *debugbackend = "native";
const char *asmarch = NULL; const char *asmarch = NULL;
@ -185,7 +185,6 @@ int main(int argc, char **argv) {
RList *cmds = r_list_new (); RList *cmds = r_list_new ();
RList *evals = r_list_new (); RList *evals = r_list_new ();
int cmdfilei = 0; int cmdfilei = 0;
file[0] = 0;
if (r_sys_getenv ("R_DEBUG")) if (r_sys_getenv ("R_DEBUG"))
r_sys_crash_handler ("gdb --pid %d"); r_sys_crash_handler ("gdb --pid %d");
@ -303,7 +302,6 @@ int main(int argc, char **argv) {
if (asmos) r_config_set (r.config, "asm.bits", asmos); if (asmos) r_config_set (r.config, "asm.bits", asmos);
if (debug) { if (debug) {
int filelen = 0;
r_config_set (r.config, "io.va", "false"); // implicit? r_config_set (r.config, "io.va", "false"); // implicit?
r_config_set (r.config, "cfg.debug", "true"); r_config_set (r.config, "cfg.debug", "true");
perms = R_IO_READ | R_IO_WRITE; perms = R_IO_READ | R_IO_WRITE;
@ -330,37 +328,20 @@ int main(int argc, char **argv) {
const char *f = argv[optind]; const char *f = argv[optind];
char *ptr; char *ptr;
is_gdb = (!memcmp (argv[optind], "gdb://", 6)); is_gdb = (!memcmp (argv[optind], "gdb://", 6));
if (is_gdb) *file = 0; if (!is_gdb) file = strdup ("dbg://");
else memcpy (file, "dbg://", 7);
/* implicit ./ to make unix behave like windows */ /* implicit ./ to make unix behave like windows */
if (*f!='/' && *f!='.' && r_file_exists (argv[optind])) { if (*f!='/' && *f!='.' && r_file_exists (argv[optind])) {
ptr = r_str_prefix (strdup (argv[optind]), "./"); ptr = r_str_prefix (strdup (argv[optind]), "./");
} else ptr = r_file_path (argv[optind]); } else ptr = r_file_path (argv[optind]);
optind++; optind++;
strcat (file, ptr); file = r_str_concat (file, ptr);
if (optind <argc) if (optind <argc)
strcat (file, " "); strcat (file, " ");
filelen = strlen (file);
while (optind < argc) { while (optind < argc) {
int largv = strlen (argv[optind]); file = r_str_concat (file, argv[optind]);
if (filelen+largv+1>=sizeof (file)) { optind++;
eprintf ("Too long arguments\n");
return 1;
}
memcpy (file+filelen, argv[optind], largv);
filelen += largv;
if (filelen+6>=sizeof (file)) {
eprintf ("Too long arguments\n");
return 1;
}
optind++;
if (optind<argc) if (optind<argc)
memcpy (file+filelen, " ", 2); file = r_str_concat (file, " ");
filelen += 2;
if (optind != argc) {
memcpy (file+filelen, " ", 2);
filelen += 2;
}
} }
if (!r_core_bin_load (&r, file)) { if (!r_core_bin_load (&r, file)) {
RBinObject *obj = r_bin_get_object (r.bin); RBinObject *obj = r_bin_get_object (r.bin);
@ -368,12 +349,8 @@ optind++;
eprintf ("bits %d\n", obj->info->bits); eprintf ("bits %d\n", obj->info->bits);
} }
fh = r_core_file_open (&r, file, perms, mapaddr); fh = r_core_file_open (&r, file, perms, mapaddr);
if (fh != NULL) { if (fh != NULL)
//const char *arch = r_config_get (r.config, "asm.arch"); r_debug_use (r.dbg, is_gdb? "gdb": debugbackend);
// TODO: move into if (debug) ..
if (is_gdb) r_debug_use (r.dbg, "gdb");
else r_debug_use (r.dbg, debugbackend);
}
} }
} }
@ -439,7 +416,7 @@ optind++;
const char *filepath = NULL; const char *filepath = NULL;
if (debug) { if (debug) {
// XXX: this is incorrect for PIE binaries // XXX: this is incorrect for PIE binaries
filepath = strstr (file, "://"); filepath = file? strstr (file, "://"): NULL;
if (filepath) filepath += 3; if (filepath) filepath += 3;
else filepath = pfile; else filepath = pfile;
} }
@ -614,5 +591,6 @@ optind++;
r_core_file_close (&r, fh); r_core_file_close (&r, fh);
r_core_fini (&r); r_core_fini (&r);
r_cons_set_raw (0); r_cons_set_raw (0);
free (file);
return ret; return ret;
} }