2015年11月11日 星期三

[C] Insert work in front of string && Debug it

Compile following code
gcc -Wall -g -Og c.c

#include<stdio.h>

static char *
no_prefix (const char *s)
{
  static char buffer[1024];
  static char *p = buffer;

  char *cp = p;
  int size = 3 + strlen (s) + 1;  /* "no-STRING\0" */
  if (p + size >= buffer + sizeof (buffer))
    abort ();

  cp[0] = 'n', cp[1] = 'o', cp[2] = '-';
  strcpy (cp + 3, s);
  p += size;
  return cp;
}

int main()
{
    printf("%s",no_prefix("no-jump"));
}

Two method to debug
1.
gdb -q a.out

2.
ddd ./a.out

Reference:

Related Posts:

0 意見:

張貼留言