1/* 2 * CodeView debugging formats implementation for Yasm 3 * 4 * Copyright (C) 2006-2007 Peter Johnson 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 */ 27#include <util.h> 28 29#include <libyasm.h> 30 31#include "cv-dbgfmt.h" 32 33yasm_dbgfmt_module yasm_cv8_LTX_dbgfmt; 34 35 36static /*@null@*/ /*@only@*/ yasm_dbgfmt * 37cv_dbgfmt_create(yasm_object *object, yasm_dbgfmt_module *module, int version) 38{ 39 yasm_dbgfmt_cv *dbgfmt_cv = yasm_xmalloc(sizeof(yasm_dbgfmt_cv)); 40 size_t i; 41 42 dbgfmt_cv->dbgfmt.module = module; 43 44 dbgfmt_cv->filenames_allocated = 32; 45 dbgfmt_cv->filenames_size = 0; 46 dbgfmt_cv->filenames = 47 yasm_xmalloc(sizeof(cv_filename)*dbgfmt_cv->filenames_allocated); 48 for (i=0; i<dbgfmt_cv->filenames_allocated; i++) { 49 dbgfmt_cv->filenames[i].pathname = NULL; 50 dbgfmt_cv->filenames[i].filename = NULL; 51 dbgfmt_cv->filenames[i].str_off = 0; 52 dbgfmt_cv->filenames[i].info_off = 0; 53 } 54 55 dbgfmt_cv->version = version; 56 57 return (yasm_dbgfmt *)dbgfmt_cv; 58} 59 60static /*@null@*/ /*@only@*/ yasm_dbgfmt * 61cv8_dbgfmt_create(yasm_object *object) 62{ 63 return cv_dbgfmt_create(object, &yasm_cv8_LTX_dbgfmt, 8); 64} 65 66static void 67cv_dbgfmt_destroy(/*@only@*/ yasm_dbgfmt *dbgfmt) 68{ 69 yasm_dbgfmt_cv *dbgfmt_cv = (yasm_dbgfmt_cv *)dbgfmt; 70 size_t i; 71 for (i=0; i<dbgfmt_cv->filenames_size; i++) { 72 if (dbgfmt_cv->filenames[i].pathname) 73 yasm_xfree(dbgfmt_cv->filenames[i].pathname); 74 } 75 yasm_xfree(dbgfmt_cv->filenames); 76 yasm_xfree(dbgfmt); 77} 78 79/* Add a bytecode to a section, updating offset on insertion; 80 * no optimization necessary. 81 */ 82yasm_bytecode * 83yasm_cv__append_bc(yasm_section *sect, yasm_bytecode *bc) 84{ 85 yasm_bytecode *precbc = yasm_section_bcs_last(sect); 86 bc->offset = yasm_bc_next_offset(precbc); 87 yasm_section_bcs_append(sect, bc); 88 return precbc; 89} 90 91static void 92cv_dbgfmt_generate(yasm_object *object, yasm_linemap *linemap, 93 yasm_errwarns *errwarns) 94{ 95 yasm_cv__generate_symline(object, linemap, errwarns); 96 yasm_cv__generate_type(object); 97} 98 99/* Define dbgfmt structure -- see dbgfmt.h for details */ 100yasm_dbgfmt_module yasm_cv8_LTX_dbgfmt = { 101 "CodeView debugging format for VC8", 102 "cv8", 103 NULL, /* no directives */ 104 cv8_dbgfmt_create, 105 cv_dbgfmt_destroy, 106 cv_dbgfmt_generate 107}; 108