Samir Baid
Samir Baid

Reputation: 1178

debugging core files

I want to write a program which can read core files in Linux. However i cannot find any documentation which can guide me in this respect. Can someone please guide me as to where to do find some resources?

Upvotes: 1

Views: 142

Answers (3)

Sir. Hedgehog
Sir. Hedgehog

Reputation: 1290

Core files can be examined by using the dbx(1) or mdb(1) or one of the proc(1) tools.

Upvotes: 0

Kevin
Kevin

Reputation: 4727

You can also take a look at GDB source code, gdb/core*.

For instance, in gdb/corelow.c, you can read at the end:

  static struct target_ops core_ops;

  core_ops.to_shortname = "core";
  core_ops.to_longname = "Local core dump file";
  core_ops.to_doc = "Use a core file as a target.  Specify the filename of the core file.";
  core_ops.to_open = core_open;
  core_ops.to_close = core_close;
  core_ops.to_attach = find_default_attach;
  core_ops.to_detach = core_detach;
  core_ops.to_fetch_registers = get_core_registers;
  core_ops.to_xfer_partial = core_xfer_partial;
  core_ops.to_files_info = core_files_info;
  core_ops.to_insert_breakpoint = ignore;
  core_ops.to_remove_breakpoint = ignore;
  core_ops.to_create_inferior = find_default_create_inferior;
  core_ops.to_thread_alive = core_thread_alive;
  core_ops.to_read_description = core_read_description;
  core_ops.to_pid_to_str = core_pid_to_str;
  core_ops.to_stratum = process_stratum;
  core_ops.to_has_memory = core_has_memory;
  core_ops.to_has_stack = core_has_stack;
  core_ops.to_has_registers = core_has_registers;

The struct target_ops defines a generic interface that the upper part of GDB will use to communicate with a target. This target can be a local unix process, a remote process, a core file, ...

So if you only investigate what's behing these functions, you won't be overhelmed by the generic part of the debugger implementation.

(depending of what's your final goal, you may also want to reuse this interface and its implementation in your app, it shouldn't rely on so many other things.

Upvotes: 1

steve
steve

Reputation: 6020

Having a look at the source of gcore http://people.redhat.com/anderson/extensions/gcore.c might be helpful.

Upvotes: 0

Related Questions