]>
git.proxmox.com Git - rustc.git/blob - vendor/gimli-0.23.0/src/write/dwarf.rs
3 use crate::common
::Encoding
;
5 AbbreviationTable
, LineProgram
, LineStringTable
, Result
, Sections
, StringTable
, Unit
,
9 /// Writable DWARF information for more than one unit.
10 #[derive(Debug, Default)]
12 /// A table of units. These are primarily stored in the `.debug_info` section,
13 /// but they also contain information that is stored in other sections.
16 /// Extra line number programs that are not associated with a unit.
18 /// These should only be used when generating DWARF5 line-only debug
20 pub line_programs
: Vec
<LineProgram
>,
22 /// A table of strings that will be stored in the `.debug_line_str` section.
23 pub line_strings
: LineStringTable
,
25 /// A table of strings that will be stored in the `.debug_str` section.
26 pub strings
: StringTable
,
30 /// Create a new `Dwarf` instance.
32 pub fn new() -> Self {
36 /// Write the DWARF information to the given sections.
37 pub fn write
<W
: Writer
>(&mut self, sections
: &mut Sections
<W
>) -> Result
<()> {
38 let line_strings
= self.line_strings
.write(&mut sections
.debug_line_str
)?
;
39 let strings
= self.strings
.write(&mut sections
.debug_str
)?
;
40 self.units
.write(sections
, &line_strings
, &strings
)?
;
41 for line_program
in &self.line_programs
{
43 &mut sections
.debug_line
,
44 line_program
.encoding(),
53 /// Writable DWARF information for a single unit.
55 pub struct DwarfUnit
{
56 /// A unit. This is primarily stored in the `.debug_info` section,
57 /// but also contains information that is stored in other sections.
60 /// A table of strings that will be stored in the `.debug_line_str` section.
61 pub line_strings
: LineStringTable
,
63 /// A table of strings that will be stored in the `.debug_str` section.
64 pub strings
: StringTable
,
68 /// Create a new `DwarfUnit`.
70 /// Note: you should set `self.unit.line_program` after creation.
71 /// This cannot be done earlier because it may need to reference
72 /// `self.line_strings`.
73 pub fn new(encoding
: Encoding
) -> Self {
74 let unit
= Unit
::new(encoding
, LineProgram
::none());
77 line_strings
: LineStringTable
::default(),
78 strings
: StringTable
::default(),
82 /// Write the DWARf information to the given sections.
83 pub fn write
<W
: Writer
>(&mut self, sections
: &mut Sections
<W
>) -> Result
<()> {
84 let line_strings
= self.line_strings
.write(&mut sections
.debug_line_str
)?
;
85 let strings
= self.strings
.write(&mut sections
.debug_str
)?
;
87 let abbrev_offset
= sections
.debug_abbrev
.offset();
88 let mut abbrevs
= AbbreviationTable
::default();
97 // None should exist because we didn't give out any UnitId.
98 assert
!(sections
.debug_info_refs
.is_empty());
99 assert
!(sections
.debug_loc_refs
.is_empty());
100 assert
!(sections
.debug_loclists_refs
.is_empty());
102 abbrevs
.write(&mut sections
.debug_abbrev
)?
;
107 #[cfg(feature = "read")]
108 pub(crate) mod convert
{
110 use crate::read
::{self, Reader}
;
111 use crate::write
::{Address, ConvertResult}
;
114 /// Create a `write::Dwarf` by converting a `read::Dwarf`.
116 /// `convert_address` is a function to convert read addresses into the `Address`
117 /// type. For non-relocatable addresses, this function may simply return
118 /// `Address::Constant(address)`. For relocatable addresses, it is the caller's
119 /// responsibility to determine the symbol and addend corresponding to the address
120 /// and return `Address::Symbol { symbol, addend }`.
121 pub fn from
<R
: Reader
<Offset
= usize>>(
122 dwarf
: &read
::Dwarf
<R
>,
123 convert_address
: &dyn Fn(u64) -> Option
<Address
>,
124 ) -> ConvertResult
<Dwarf
> {
125 let mut line_strings
= LineStringTable
::default();
126 let mut strings
= StringTable
::default();
127 let units
= UnitTable
::from(dwarf
, &mut line_strings
, &mut strings
, convert_address
)?
;
128 // TODO: convert the line programs that were not referenced by a unit.
129 let line_programs
= Vec
::new();