From 72104c98162ef3f9b03ba46c95a99c6ee0caf928 Mon Sep 17 00:00:00 2001 From: Dmitry Bravikov Date: Tue, 8 Nov 2011 09:41:43 +0600 Subject: [PATCH] [fix] parsing command line and sg autodetection --- gdbserver/gdb-server.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gdbserver/gdb-server.c b/gdbserver/gdb-server.c index 1254232..303a4a9 100644 --- a/gdbserver/gdb-server.c +++ b/gdbserver/gdb-server.c @@ -119,9 +119,14 @@ int main(int argc, char** argv) { // if (p == 0) ... + if (sl != NULL) { + fprintf(stderr, "Invalid argumets\n"); + fprintf(stderr, HelpStr, NULL); + return 1; + } + // usb if (!strcmp(argv[a], "usb")) { - if (sl != NULL) return 1; sl = stlink_open_usb(10); if(sl == NULL) return 1; continue; @@ -133,7 +138,6 @@ int main(int argc, char** argv) { fprintf(stderr, "libsg not use\n"); return 1; } - if (sl != NULL) return 1; sl = stlink_quirk_open(argv[a], 0); if(sl == NULL) return 1; continue; @@ -149,7 +153,6 @@ int main(int argc, char** argv) { // Search ST-LINK (from /dev/sg0 to /dev/sg99) for(int DevNum = 0; DevNum <= 99; DevNum++) { - if(sl != NULL) return 1; if(DevNum < 10) { char DevName[] = "/dev/sgX"; DevName[7] = DevNum + '0'; @@ -163,7 +166,7 @@ int main(int argc, char** argv) { if ( !access(DevName, F_OK) ) sl = stlink_quirk_open(DevName, 0); } - + if (sl != NULL) break; } if(sl == NULL) return 1; @@ -181,6 +184,8 @@ int main(int argc, char** argv) { // Default port: 4242 if (port == 0) port = 4242; + // End parsing + if (sl == NULL) return 1;