1d65182f1818d1c19e6f3866ab6e68a262fad5185hbono@chromium.org/*
245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * DWARF2 debugging format
345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *
445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *  Copyright (C) 2006-2007  Peter Johnson
545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *
645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Redistribution and use in source and binary forms, with or without
745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * modification, are permitted provided that the following conditions
845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * are met:
945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 1. Redistributions of source code must retain the above copyright
1045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *    notice, this list of conditions and the following disclaimer.
1145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 2. Redistributions in binary form must reproduce the above copyright
1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *    notice, this list of conditions and the following disclaimer in the
1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *    documentation and/or other materials provided with the distribution.
1445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *
1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * POSSIBILITY OF SUCH DAMAGE.
2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef YASM_DWARF2_DBGFMT_H
2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_DWARF2_DBGFMT_H
2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
3045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define WITH_DWARF3 1
3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct {
3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    char *pathname;         /* full filename */
3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    char *filename;         /* basename of full filename */
3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned long dir;      /* index into directories array for relative path;
3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                             * 0 for current directory. */
3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} dwarf2_filename;
3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* Global data */
4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_dbgfmt_dwarf2 {
4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    yasm_dbgfmt_base dbgfmt;        /* base structure */
4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    char **dirs;
4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned long dirs_size;
4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned long dirs_allocated;
4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    dwarf2_filename *filenames;
4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned long filenames_size;
4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned long filenames_allocated;
5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    enum {
5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        DWARF2_FORMAT_32BIT,
5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        DWARF2_FORMAT_64BIT
5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    } format;
5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int sizeof_address, sizeof_offset, min_insn_len;
5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} yasm_dbgfmt_dwarf2;
5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* .loc directive data */
6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct dwarf2_loc {
6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /*@reldef@*/ STAILQ_ENTRY(dwarf2_loc) link;
6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned long vline;    /* virtual line number of .loc directive */
6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /* source information */
6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned long file;     /* index into table of filenames */
6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned long line;     /* source line number */
6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned long column;   /* source column */
69d65182f1818d1c19e6f3866ab6e68a262fad5185hbono@chromium.org    unsigned long discriminator;
7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    int isa_change;
7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned long isa;
7245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    enum {
7345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        IS_STMT_NOCHANGE = 0,
7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        IS_STMT_SET,
7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        IS_STMT_CLEAR
7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    } is_stmt;
7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    int basic_block;
7845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    int prologue_end;
7945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    int epilogue_begin;
8045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
8145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    yasm_bytecode *bc;      /* first bytecode following */
8245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    yasm_symrec *sym;       /* last symbol preceding */
8345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} dwarf2_loc;
8445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
8545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* Per-section data */
8645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct dwarf2_section_data {
8745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /* The locations set by the .loc directives in this section, in assembly
8845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * source order.
8945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
9045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /*@reldef@*/ STAILQ_HEAD(dwarf2_lochead, dwarf2_loc) locs;
9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} dwarf2_section_data;
9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgextern const yasm_assoc_data_callback yasm_dwarf2__section_data_cb;
9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
9545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_bytecode *yasm_dwarf2__append_bc(yasm_section *sect, yasm_bytecode *bc);
9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@dependent@*/ yasm_symrec *yasm_dwarf2__bc_sym(yasm_symtab *symtab,
9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                                 yasm_bytecode *bc);
9945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
10045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct dwarf2_head dwarf2_head;
10145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgdwarf2_head *yasm_dwarf2__add_head
10245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    (yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2, yasm_section *sect,
10345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     /*@null@*/ yasm_section *debug_ptr, int with_address, int with_segment);
10445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_dwarf2__set_head_end(dwarf2_head *head, yasm_bytecode *end_prevbc);
10545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
10645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* Line number functions */
10745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_section *yasm_dwarf2__generate_line
10845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    (yasm_object *object, yasm_linemap *linemap, yasm_errwarns *errwarns,
10945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     int asm_source, /*@out@*/ yasm_section **main_code,
11045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     /*@out@*/ size_t *num_line_sections);
11145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_dwarf2__dir_loc(yasm_object *object, yasm_valparamhead *valparams,
11245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                          yasm_valparamhead *objext_valparams,
11345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                          unsigned long line);
11445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_dwarf2__dir_file(yasm_object *object, yasm_valparamhead *valparams,
11545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                           yasm_valparamhead *objext_valparams,
11645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                           unsigned long line);
11745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
11845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* Address range table functions */
11945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_section *yasm_dwarf2__generate_aranges(yasm_object *object,
12045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                            yasm_section *debug_info);
12145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
12245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* Name lookup table functions */
12345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_section *yasm_dwarf2__generate_pubnames(yasm_object *object,
12445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                             yasm_section *debug_info);
12545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
12645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* Information functions */
12745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_section *yasm_dwarf2__generate_info
12845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    (yasm_object *object, yasm_section *debug_line,
12945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     /*@null@*/ yasm_section *main_code);
13045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
13145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif
132