Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2002:
[Freeciv-Dev] Re: autobacktrace (was: concerning the use of assert)
Home

[Freeciv-Dev] Re: autobacktrace (was: concerning the use of assert)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Reinier Post <rp@xxxxxxxxxx>
Cc: Freeciv Developers <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: autobacktrace (was: concerning the use of assert)
From: "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx>
Date: Sun, 22 Sep 2002 21:48:44 -0400

This is not quite what you asked for, but it might be a useful example
towards getting something a little more robust than a scripted solution
for LOG_DEBUG purposes.

Cheers,
RossW
=====

At 09:01 AM 02/09/16 +0200, Reinier Post wrote:
>BTW if someone can take charge of getting cores and maintaining the
>civserver-core-backtrace on civserver.frreeciv.org I would appreciate it.
>
>(I haven't been using gdb in a while, and there's enough work to do.)
>
>-- 
>Reinier
=====

/*
 * Stacktrace 
 *   demo program to print a stacktrace to stderr from a running program
 *
 * HowTo:
 *   cc -o stacktrace stacktrace.c
 *   ./stacktrace
 */

#include <limits.h>
#include <stdio.h>

char *progname;

void print_stacktrace()
{
  static char *pbuf, buf[PATH_MAX], line[PATH_MAX];
  FILE *pin;

  if (buf[0] == 0) {
    snprintf(buf, sizeof(buf),
      "gdb %s %d <<EOF\n"
      "where\n"
      "quit\n"
      "EOF",
      progname, getpid());
  }

  fflush(stderr);
  if ((pin = popen(buf, "r"))) {
    while( (pbuf = fgets(line, sizeof(line)-1, pin)) )
      fprintf(stderr, pbuf);
    pclose(pin);
  }
}

int main(int argc, char *argv[], char* argp[])
{
  fprintf(stderr, "Starting %s ...\n\n", argv[0]);

  progname = argv[0];
  print_stacktrace();

  fprintf(stderr, "\nDone\n");
  exit(0);
}
=====




[Prev in Thread] Current Thread [Next in Thread]