Skip to content

Instantly share code, notes, and snippets.

@igorljubuncic
Last active May 13, 2021
Embed
What would you like to do?

How to troubleshoot application issues and crashes with snapd gdbserver

This gist includes all the tools and scripts used in the following blog post:
https://snapcraft.io/blog/how-to-troubleshoot-application-issues-and-crashes-with-snapd-gdbserver

segfexample.c source code:

#include <stdio.h>
#include <stdlib.h>

main()
{
   int *pointer;
   int i;
   pointer = malloc(sizeof(int));
   for (i = 0; 1; i++)
   {
      pointer[i]=i;
      printf("pointer[%d] = %d\n", i, pointer[i]);
   }
   return(0);
}

segfexample.c compilation:

gcc -g segfexample.c -o segfexample

You will need to have gcc installed on your Linux system. Once you have the compiled application, copy it into a sub-folder in your snap workspace directory. For example, copy segexample into snap/binary.

segfexample snapcraft.yaml

name: segfexample
base: core20 
version: '1.0'
summary: GDB segfault example snap
description: |
  GDB test snap designed to crash on purposes.

grade: stable
confinement: strict 

parts:
  segfexample:
    plugin: dump
    source: binary/
apps:
  segfexample:
    command: segfexample
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment