Search code examples
linuxdebugginggdbcoredump

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?


Solution

  • 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.