dwarf2-aranges.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * DWARF2 debugging format - address range table
  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. #include <libyasm.h>
  29. #include "dwarf2-dbgfmt.h"
  30. static void
  31. dwarf2_append_arange(yasm_section *debug_aranges, /*@only@*/ yasm_expr *start,
  32. /*@only@*/ yasm_expr *length, unsigned int sizeof_address)
  33. {
  34. yasm_datavalhead dvs;
  35. yasm_bytecode *bc;
  36. yasm_dvs_initialize(&dvs);
  37. yasm_dvs_append(&dvs, yasm_dv_create_expr(start));
  38. yasm_dvs_append(&dvs, yasm_dv_create_expr(length));
  39. bc = yasm_bc_create_data(&dvs, sizeof_address, 0, NULL, 0);
  40. yasm_bc_finalize(bc, yasm_dwarf2__append_bc(debug_aranges, bc));
  41. yasm_bc_calc_len(bc, NULL, NULL);
  42. }
  43. typedef struct dwarf2_aranges_info {
  44. yasm_section *debug_aranges; /* section to which address ranges go */
  45. yasm_object *object;
  46. yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2;
  47. } dwarf2_aranges_info;
  48. static int
  49. dwarf2_generate_aranges_section(yasm_section *sect, /*@null@*/ void *d)
  50. {
  51. dwarf2_aranges_info *info = (dwarf2_aranges_info *)d;
  52. yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2 = info->dbgfmt_dwarf2;
  53. /*@null@*/ dwarf2_section_data *dsd;
  54. /*@only@*/ yasm_expr *start, *length;
  55. dsd = yasm_section_get_data(sect, &yasm_dwarf2__section_data_cb);
  56. if (!dsd)
  57. return 0; /* no line data for this section */
  58. /* Create address range descriptor */
  59. start = yasm_expr_create_ident(
  60. yasm_expr_sym(yasm_dwarf2__bc_sym(info->object->symtab,
  61. yasm_section_bcs_first(sect))), 0);
  62. length = yasm_expr_create_ident(
  63. yasm_expr_int(yasm_calc_bc_dist(yasm_section_bcs_first(sect),
  64. yasm_section_bcs_last(sect))), 0);
  65. dwarf2_append_arange(info->debug_aranges, start, length,
  66. dbgfmt_dwarf2->sizeof_address);
  67. return 0;
  68. }
  69. yasm_section *
  70. yasm_dwarf2__generate_aranges(yasm_object *object, yasm_section *debug_info)
  71. {
  72. yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2 = (yasm_dbgfmt_dwarf2 *)object->dbgfmt;
  73. int new;
  74. yasm_section *debug_aranges;
  75. yasm_bytecode *bc;
  76. dwarf2_head *head;
  77. dwarf2_aranges_info info;
  78. debug_aranges =
  79. yasm_object_get_general(object, ".debug_aranges",
  80. 2*dbgfmt_dwarf2->sizeof_address, 0, 0, &new,
  81. 0);
  82. /* header */
  83. head = yasm_dwarf2__add_head(dbgfmt_dwarf2, debug_aranges, debug_info, 1,
  84. 1);
  85. /* align ranges to 2x address size (range size) */
  86. bc = yasm_bc_create_align(
  87. yasm_expr_create_ident(yasm_expr_int(
  88. yasm_intnum_create_uint(dbgfmt_dwarf2->sizeof_address*2)), 0),
  89. NULL, NULL, NULL, 0);
  90. yasm_bc_finalize(bc, yasm_dwarf2__append_bc(debug_aranges, bc));
  91. yasm_bc_calc_len(bc, NULL, NULL);
  92. info.debug_aranges = debug_aranges;
  93. info.object = object;
  94. info.dbgfmt_dwarf2 = dbgfmt_dwarf2;
  95. yasm_object_sections_traverse(object, (void *)&info,
  96. dwarf2_generate_aranges_section);
  97. /* Terminate with empty address range descriptor */
  98. dwarf2_append_arange(debug_aranges,
  99. yasm_expr_create_ident(yasm_expr_int(yasm_intnum_create_uint(0)), 0),
  100. yasm_expr_create_ident(yasm_expr_int(yasm_intnum_create_uint(0)), 0),
  101. dbgfmt_dwarf2->sizeof_address);
  102. /* mark end of aranges information */
  103. yasm_dwarf2__set_head_end(head, yasm_section_bcs_last(debug_aranges));
  104. return debug_aranges;
  105. }