OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #region | |
6 | |
7 using System.Collections.Generic; | |
8 using NaClVsx; | |
9 | |
10 #endregion | |
11 | |
12 namespace Google.NaClVsx.DebugSupport.DWARF { | |
13 /// <summary> | |
14 /// Represent a debug information entry. | |
15 /// </summary> | |
16 public class DebugInfoEntry { | |
17 /// <summary> | |
18 /// Adds a RangeListEntry for a given address, provided the DIE doesn't al
ready contain one | |
19 /// for that address. | |
20 /// </summary> | |
21 /// <param name = "address">The address. Note that this list is expected to
be the address at | |
22 /// runtime, not just the LowPC values from the rangeListEntry.</param> | |
23 /// <param name = "rangeListEntry">The RangeList entry to be added to this D
IE.</param> | |
24 public void AddRangeListEntryByAddress(ulong address, RangeListEntry rangeLi
stEntry) { | |
25 if (!RangeListsByAddress.ContainsKey(address)) { | |
26 RangeListsByAddress.Add(address, rangeListEntry); | |
27 } | |
28 } | |
29 | |
30 /// <summary> | |
31 /// Gets the nearest ancestor of this DIE with a requested DwarfTag. | |
32 /// </summary> | |
33 /// <param name = "tag">The tag that must be matched.</param> | |
34 /// <returns>The innermost DIE that has the requested DwarfTag. If this | |
35 /// DIE matches it returns itself. If no ancestor matches, the function | |
36 /// will return NULL.</returns> | |
37 public DebugInfoEntry GetNearestAncestorWithTag(DwarfTag tag) { | |
38 var target = this; | |
39 while (target.Tag != tag && target.OuterScope != null) { | |
40 target = target.OuterScope; | |
41 } | |
42 if (target.Tag != tag) { | |
43 return null; | |
44 } | |
45 return target; | |
46 } | |
47 | |
48 /// <summary> | |
49 /// Gets the Frame Base address if this DIE has one. | |
50 /// </summary> | |
51 /// <returns>The frame base address or 0 if this DIE doesn't have one. | |
52 /// </returns> | |
53 public ulong GetFrameBase() { | |
54 return (ulong) Attributes.GetValueOrDefault( | |
55 DwarfAttribute.DW_AT_frame_base, (ulong) 0); | |
56 } | |
57 | |
58 /// <summary> | |
59 /// Gets the LowPC address if this DIE has one. | |
60 /// </summary> | |
61 /// <returns>The frame base address or 0 if this DIE doesn't have one. | |
62 /// </returns> | |
63 public ulong GetLowPC() { | |
64 return (ulong) Attributes.GetValueOrDefault( | |
65 DwarfAttribute.DW_AT_low_pc, (ulong) 0); | |
66 } | |
67 | |
68 /// <summary> | |
69 /// Gets the offset of this DIE's ranges entry in. The offset can be used
as a key to | |
70 /// retrieve the ranges entry from the SymbolDatabase. | |
71 /// </summary> | |
72 /// <returns>The offset if this DIE has a ranges entry, ulong.MaxValue if it
doesn't. | |
73 /// </returns> | |
74 public ulong GetRangesOffset() { | |
75 return (ulong) Attributes.GetValueOrDefault( | |
76 DwarfAttribute.DW_AT_ranges, ulong.MaxValue); | |
77 } | |
78 | |
79 /// <summary> | |
80 /// Determines whether this DebugInformationEntry has an ancestor whose ke
y is | |
81 /// |ancestorKey|. | |
82 /// </summary> | |
83 /// <param name = "ancestorKey">The key of the possible ancestor's entry in
the symbol | |
84 /// database.</param> | |
85 /// <returns>True iff this DIE has an ancestor with key |ancestorKey|.</retu
rns> | |
86 public bool HasAsAncestor(ulong ancestorKey) { | |
87 var ancestor = OuterScope; | |
88 while (ancestor != null) { | |
89 if (ancestor.Key == ancestorKey) { | |
90 return true; | |
91 } | |
92 ancestor = ancestor.OuterScope; | |
93 } | |
94 return false; | |
95 } | |
96 | |
97 /// <summary> | |
98 /// Checks whether this DIE has a given attribute. Different DIEs have di
fferent | |
99 /// attributes. For a complete list, see NaClVsx.DebugHelpers\DwarfParser
.h | |
100 /// </summary> | |
101 /// <param name = "attribute">The attribute to be checked.</param> | |
102 /// <returns>True iff this DIE has the given attribute.</returns> | |
103 public bool HasAttribute(DwarfAttribute attribute) { | |
104 return Attributes.ContainsKey(attribute); | |
105 } | |
106 | |
107 public ulong Key; | |
108 public DwarfTag Tag; | |
109 public ulong ParentKey; | |
110 public DebugInfoEntry OuterScope; | |
111 | |
112 public Dictionary<DwarfAttribute, object> Attributes = | |
113 new Dictionary<DwarfAttribute, object>(); | |
114 | |
115 public Dictionary<ulong, RangeListEntry> RangeListsByAddress = | |
116 new Dictionary<ulong, RangeListEntry>(); | |
117 } | |
118 } | |
OLD | NEW |