gitee.com/mysnapcore/mysnapd@v0.1.0/cmd/snap-gdb-shim/snap-gdb-shim.c (about) 1 /* 2 * Copyright (C) 2018 Canonical Ltd 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License version 3 as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 * 16 */ 17 18 #include <signal.h> 19 #include <stdio.h> 20 #include <stdlib.h> 21 #include <unistd.h> 22 23 #include "../libsnap-confine-private/utils.h" 24 25 int main(int argc, char **argv) { 26 if (sc_is_debug_enabled()) { 27 for (int i = 0; i < argc; i++) { 28 fprintf(stderr, "-%s-\n", argv[i]); 29 } 30 } 31 if (argc < 2) { 32 fprintf(stderr, "missing a command to execute"); 33 abort(); 34 } 35 // signal gdb to stop here 36 printf("\n\n"); 37 printf("DEPRECATED: Please consider using --gdbserver instead.\n"); 38 printf("\n"); 39 printf("Welcome to `snap run --gdb`.\n"); 40 printf("You are right before your application is execed():\n"); 41 printf("- set any options you may need\n"); 42 printf("- use 'cont' to start\n"); 43 printf("\n\n"); 44 raise(SIGTRAP); 45 46 const char *executable = argv[1]; 47 execv(executable, (char *const *)&argv[1]); 48 perror("execv failed"); 49 // very different exit code to make an execve failure easy to distinguish 50 return 101; 51 }