github.com/rigado/snapd@v2.42.5-go-mod+incompatible/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 { 27 if (sc_is_debug_enabled()) { 28 for (int i = 0; i < argc; i++) { 29 printf("-%s-\n", argv[i]); 30 } 31 } 32 // signal gdb to stop here 33 printf("\n\n"); 34 printf("Welcome to `snap run --gdb`.\n"); 35 printf("You are right before your application is execed():\n"); 36 printf("- set any options you may need\n"); 37 printf("- use 'cont' to start\n"); 38 printf("\n\n"); 39 raise(SIGTRAP); 40 41 const char *executable = argv[1]; 42 execv(executable, (char *const *)&argv[1]); 43 perror("execv failed"); 44 // very different exit code to make an execve failure easy to distinguish 45 return 101; 46 }