From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7661 invoked by alias); 24 Jul 2011 16:00:11 -0000 Received: (qmail 7370 invoked by uid 22791); 24 Jul 2011 16:00:08 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_SOFTFAIL X-Spam-Check-By: sourceware.org Received: from mail-pz0-f52.google.com (HELO mail-pz0-f52.google.com) (209.85.210.52) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 24 Jul 2011 15:59:45 +0000 Received: by pzd13 with SMTP id 13so6313504pzd.25 for ; Sun, 24 Jul 2011 08:59:45 -0700 (PDT) Received: by 10.68.27.131 with SMTP id t3mr6243259pbg.487.1311523185346; Sun, 24 Jul 2011 08:59:45 -0700 (PDT) Received: from localhost.localdomain ([203.110.240.178]) by mx.google.com with ESMTPS id p7sm3758423pbn.65.2011.07.24.08.59.42 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 24 Jul 2011 08:59:44 -0700 (PDT) From: Sanjoy Das To: gdb-patches@sourceware.org Cc: Sanjoy Das Subject: [PATCH 2/4] Populates jit-reader.h.in Date: Sun, 24 Jul 2011 17:26:00 -0000 Message-Id: <1311523427-20501-3-git-send-email-sanjoy@playingwithpointers.com> In-Reply-To: <1311523427-20501-1-git-send-email-sanjoy@playingwithpointers.com> References: <1311523427-20501-1-git-send-email-sanjoy@playingwithpointers.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-07/txt/msg00669.txt.bz2 Adds the interface to be implemented by the JIT debug-info readers and the API they can use to jit-reader.h.in. gdb/ChangeLog * jit-reader.h.in: Add API and interface. * jit.c: Include jit-reader.h. --- gdb/ChangeLog | 4 + gdb/jit-reader.h.in | 196 +++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/jit.c | 1 + 3 files changed, 201 insertions(+), 0 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 2cc82bc..25281f4 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,4 +1,8 @@ 2011-07-24 Sanjoy Das + * jit-reader.h.in: Add API and interface. + * jit.c: Include jit-reader.h. + +2011-07-24 Sanjoy Das * jit-reader.h.in: New header. * config.in: Add HAVE_LIBDL and GDB_JIT_READER_PATH. diff --git a/gdb/jit-reader.h.in b/gdb/jit-reader.h.in index 94f9a95..a525ec8 100644 --- a/gdb/jit-reader.h.in +++ b/gdb/jit-reader.h.in @@ -46,6 +46,202 @@ extern "C" { /* Represents an address on the target system. */ typedef @HOST_U_64_BIT@ GDB_CORE_ADDR; +/* Return status codes. */ +enum { + GDB_FAIL = 0, + GDB_SUCCESS = 1 +}; + +#define GDB_MAX_REGISTER_SIZE 64 /* Mirrors the internal GDB definition. */ + +struct gdb_symtab; +struct gdb_block; +struct gdb_symbol; +struct gdb_symtab_callbacks; + +/* An array of these are used to represent a map from code addresses to line + numbers in the source file. */ +struct gdb_line_mapping +{ + int line; + GDB_CORE_ADDR pc; +}; + +/* The callback used to create new symbol table. + CB is the gdb_symtab_callbacks which the structure is part of. + FILE_NAME is an (optionally NULL) file name to associate with this new symbol + table. + + Returns a new instance to gdb_symtab that can later be passed to + gdb_block_new, gdb_symtab_add_line_mapping and gdb_symtab_close. +*/ +typedef struct gdb_symtab *(gdb_symtab_new) (struct gdb_symtab_callbacks *cb, + const char *file_name); + +/* Creates a new block in a given symbol table. A symbol table is a forest of + blocks, each block representing an code address range and a corresponding + (optionally NULL) NAME. In case the block corresponds to a function, the NAME + passed should be the name of the function. + + If the new block to be created is a child of (i.e. is nested in) another + block, the parent block can be passed in PARENT. SYMTAB is the symbol table + the new block is to belong in. BEGIN, END is the code address range the block + corresponds to. + + Returns a new instance of gdb_block, which, as of now, has no use. Note that + the gdb_block returned must not be freed by the caller. */ +typedef struct gdb_block *(gdb_block_new) (struct gdb_symtab_callbacks *cb, + struct gdb_symtab *symtab, + struct gdb_block *parent, + GDB_CORE_ADDR begin, + GDB_CORE_ADDR end, + const char *name); + +/* Adds a PC to line number mapping for the symbol table SYMTAB. NLINES is the + number of elements in LINES, each element corresponding to one (PC, line) + pair. */ +typedef void (gdb_symtab_add_line_mapping) (struct gdb_symtab_callbacks *cb, + struct gdb_symtab *symtab, + int nlines, + struct gdb_line_mapping *lines); + +/* Frees the symbol table SYMTAB, after adding it to GDB's internal structures. + Every gdb_symtab_new must be paired with a gdb_symtab_free. */ +typedef void (gdb_symtab_free) (struct gdb_symtab_callbacks *cb, + struct gdb_symtab *symtab); + +/* Reads LEN bytes from TARGET_MEM in the target's virtual address space into + GDB_BUF. + + Returns GDB_FAIL on failure, and GDB_SUCCESS on success. */ +typedef int (gdb_target_read) (GDB_CORE_ADDR target_mem, void *gdb_buf, + int len); + +/* The list of callbacks that are passed to read. These callbacks are to be used + to construct the symbol table. The functions have been described above. */ +struct gdb_symtab_callbacks +{ + gdb_symtab_new *symtab_open; + gdb_block_new *new_block; + gdb_symtab_add_line_mapping *add_line_mapping; + gdb_target_read *target_read; + gdb_symtab_free *symtab_close; + + /* For internal use. */ + void *private; +}; + +/* Denotes the value of a register. The value is valid only if defined is set to + non-zero. */ +struct gdb_reg_value +{ + int defined; + unsigned char value[GDB_MAX_REGISTER_SIZE]; +}; + +/* get_frame_id in gdb_reader_funcs is required to return a gdb_frame_id + corresponding to the current frame. The registers corresponding to the + current frame can be read using reg_get. A frame should correspond to the + same gdb_frame_id throughout its lifetime (i.e. before it gets unwound). This + can usually be accomplished by having the CODE_ADDRESS point to the + function's first instruction and STACK_ADDRESS point to the value of the + stack pointer when entering the function. */ +struct gdb_frame_id +{ + GDB_CORE_ADDR code_address; + GDB_CORE_ADDR stack_address; +}; + +/* Forward declaration. */ +struct gdb_unwind_callbacks; + +/* Returns the value of a particular register in the current frame. The current + frame is the frame that needs to be unwound into the outer (earlier) frame. + + CB is the struct gdb_unwind_callbacks * the callback belongs to. REGNUM is + the DWARF register number of the register that needs to be unwound. + + Returns the gdb_reg_value corresponding to the register requested. Note that + in case the value of the register has been optimized away or otherwise + unavailable, the defined flag in the returned gdb_reg_value will be zero. */ +typedef struct gdb_reg_value (gdb_unwind_reg_get) (struct gdb_unwind_callbacks * + cb, int regnum); + +/* Sets the previous value of a particular register. REGNUM is (DWARF) register + number whose value is to be set. VAL is the value the register is to be set + to. + + Note that a register can also be "set" to an undefined value by setting the + defined in VAL to zero. */ +typedef void (gdb_unwind_reg_set) (struct gdb_unwind_callbacks *cb, int regnum, + struct gdb_reg_value val); + +/* This struct is passed to unwind in gdb_reader_funcs, and is to be used to + unwind the current frame (current being the frame whose registers can be read + using reg_get) into the earlier frame. The functions have been described + above. */ +struct gdb_unwind_callbacks +{ + gdb_unwind_reg_get *reg_get; + gdb_unwind_reg_set *reg_set; + gdb_target_read *target_read; + + /* For internal use. */ + void *private; +}; + +/* Forward declaration. */ +struct gdb_reader_funcs; + +/* Tries to parse the debug info off a block of memory, pointed to by MEMORY + (already copied to GDB's address space) and MEMORY_SZ bytes long. + As mentioned, gdb_read_debug_info is expected to use the functions in + CB to actually emit the parsed data into GDB. SELF is the same structure + returned by gdb_init_reader. + + Returns GDB_FAIL on failure and GDB_SUCCESS on success. */ +typedef int (gdb_read_debug_info) (struct gdb_reader_funcs *self, + struct gdb_symtab_callbacks *cb, + void *memory, long memory_sz); + +/* Tries to unwind the current frame, CB is the set of unwind callbacks that are + to be used to do this. + + Returns GDB_FAIL on failure and GDB_SUCCESS on success. */ +typedef int (gdb_unwind_frame) (struct gdb_reader_funcs *self, + struct gdb_unwind_callbacks *cb); + +/* Returns the frame ID corresponding to the current frame, using C to read + the current register values. See the comment on struct gdb_frame_id. */ +typedef struct gdb_frame_id (gdb_get_frame_id) (struct gdb_reader_funcs *self, + struct gdb_unwind_callbacks *c); + +/* Called when a reader is being unloaded. This function should also free SELF, + in case it was malloced. */ +typedef void (gdb_destroy_reader) (struct gdb_reader_funcs *self); + +/* Called when the reader is loaded. Must either return a properly populated + gdb_reader_funcs or NULL (indicating an error). The memory allocated for + the gdb_reader_funcs is to be managed by the reader itself (i.e. if it is + allocated from the heap, it must also be freed in gdb_destroy_reader). +*/ +extern struct gdb_reader_funcs *gdb_init_reader (void); + +/* Pointer to the functions which implement the reader's functionality. + The individual functions have been documented above. + + None of the fields are optional. */ +struct gdb_reader_funcs +{ + gdb_read_debug_info *read; + gdb_unwind_frame *unwind; + gdb_get_frame_id *get_frame_id; + gdb_destroy_reader *destroy; + + /* For use by the reader. */ + void *private; +}; + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/gdb/jit.c b/gdb/jit.c index eb1bcc7..e3bb81a 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -20,6 +20,7 @@ #include "defs.h" #include "jit.h" +#include "jit-reader.h" #include "breakpoint.h" #include "command.h" #include "gdbcmd.h" -- 1.7.5.4