blob: d4b56865f12e52e8d733fb65ef2be7a0140cc3fd [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- LineEntry.cpp -------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Symbol/LineEntry.h"
11#include "lldb/Symbol/CompileUnit.h"
12#include "lldb/Target/Process.h"
Greg Claytoneea26402010-09-14 23:36:40 +000013#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000014
15using namespace lldb_private;
16
17LineEntry::LineEntry() :
18 range(),
19 file(),
20 line(0),
21 column(0),
22 is_start_of_statement(0),
23 is_start_of_basic_block(0),
Chris Lattner24943d22010-06-08 16:52:24 +000024 is_prologue_end(0),
Eric Christophercdcb1562010-07-05 19:13:23 +000025 is_epilogue_begin(0),
26 is_terminal_entry(0)
Chris Lattner24943d22010-06-08 16:52:24 +000027{
28}
29
30LineEntry::LineEntry
31(
32 lldb_private::Section *section,
33 lldb::addr_t section_offset,
34 lldb::addr_t byte_size,
35 const FileSpec &_file,
36 uint32_t _line,
37 uint16_t _column,
38 bool _is_start_of_statement,
39 bool _is_start_of_basic_block,
40 bool _is_prologue_end,
41 bool _is_epilogue_begin,
42 bool _is_terminal_entry
43) :
44 range(section, section_offset, byte_size),
45 file(_file),
46 line(_line),
47 column(_column),
48 is_start_of_statement(_is_start_of_statement),
49 is_start_of_basic_block(_is_start_of_basic_block),
50 is_prologue_end(_is_prologue_end),
51 is_epilogue_begin(_is_epilogue_begin),
52 is_terminal_entry(_is_terminal_entry)
53{
54}
55
56void
57LineEntry::Clear()
58{
59 range.Clear();
60 file.Clear();
61 line = 0;
62 column = 0;
63 is_start_of_statement = 0;
64 is_start_of_basic_block = 0;
65 is_prologue_end = 0;
66 is_epilogue_begin = 0;
67 is_terminal_entry = 0;
68}
69
70
71bool
72LineEntry::IsValid() const
73{
74 return range.GetBaseAddress().IsValid() && line != 0;
75}
76
77bool
Greg Clayton72b71582010-09-02 21:44:10 +000078LineEntry::DumpStopContext(Stream *s, bool show_fullpaths) const
Chris Lattner24943d22010-06-08 16:52:24 +000079{
80 bool result = false;
81 if (file)
82 {
Greg Clayton72b71582010-09-02 21:44:10 +000083 if (show_fullpaths)
84 file.Dump (s);
85 else
86 file.GetFilename().Dump (s);
87
Chris Lattner24943d22010-06-08 16:52:24 +000088 if (line)
89 s->PutChar(':');
90 result = true;
91 }
92 if (line)
93 s->Printf ("%u", line);
94 else
95 result = false;
96
97 return result;
98}
99
100bool
101LineEntry::Dump
102(
103 Stream *s,
Greg Claytoneea26402010-09-14 23:36:40 +0000104 Target *target,
Chris Lattner24943d22010-06-08 16:52:24 +0000105 bool show_file,
106 Address::DumpStyle style,
107 Address::DumpStyle fallback_style,
108 bool show_range
109) const
110{
111 if (show_range)
112 {
113 // Show address range
Greg Claytoneea26402010-09-14 23:36:40 +0000114 if (!range.Dump(s, target, style, fallback_style))
Chris Lattner24943d22010-06-08 16:52:24 +0000115 return false;
116 }
117 else
118 {
119 // Show address only
120 if (!range.GetBaseAddress().Dump(s,
Greg Claytoneea26402010-09-14 23:36:40 +0000121 target,
Chris Lattner24943d22010-06-08 16:52:24 +0000122 style,
123 fallback_style))
124 return false;
125 }
Greg Clayton12bec712010-06-28 21:30:43 +0000126 if (show_file)
127 *s << ", file = " << file;
Chris Lattner24943d22010-06-08 16:52:24 +0000128 if (line)
129 s->Printf(", line = %u", line);
130 if (column)
131 s->Printf(", column = %u", column);
Chris Lattner24943d22010-06-08 16:52:24 +0000132 if (is_start_of_statement)
133 *s << ", is_start_of_statement = TRUE";
134
135 if (is_start_of_basic_block)
136 *s << ", is_start_of_basic_block = TRUE";
137
138 if (is_prologue_end)
139 *s << ", is_prologue_end = TRUE";
140
141 if (is_epilogue_begin)
142 *s << ", is_epilogue_begin = TRUE";
143
144 if (is_terminal_entry)
145 *s << ", is_terminal_entry = TRUE";
146 return true;
147}
148
149bool
Greg Claytoneea26402010-09-14 23:36:40 +0000150LineEntry::GetDescription (Stream *s, lldb::DescriptionLevel level, CompileUnit* cu, Target *target, bool show_address_only) const
Chris Lattner24943d22010-06-08 16:52:24 +0000151{
152
153 if (level == lldb::eDescriptionLevelBrief || level == lldb::eDescriptionLevelFull)
154 {
Greg Clayton12bec712010-06-28 21:30:43 +0000155 if (show_address_only)
156 {
Greg Claytoneea26402010-09-14 23:36:40 +0000157 range.GetBaseAddress().Dump(s, target, Address::DumpStyleLoadAddress, Address::DumpStyleFileAddress);
Greg Clayton12bec712010-06-28 21:30:43 +0000158 }
159 else
160 {
Greg Claytoneea26402010-09-14 23:36:40 +0000161 range.Dump(s, target, Address::DumpStyleLoadAddress, Address::DumpStyleFileAddress);
Greg Clayton12bec712010-06-28 21:30:43 +0000162 }
Chris Lattner24943d22010-06-08 16:52:24 +0000163
Greg Claytonc67b7d12010-09-10 01:30:46 +0000164 *s << ": " << file;
Chris Lattner24943d22010-06-08 16:52:24 +0000165
166 if (line)
167 {
168 s->Printf(":%u", line);
169 if (column)
170 s->Printf(":%u", column);
171 }
172
Greg Claytonc67b7d12010-09-10 01:30:46 +0000173
Chris Lattner24943d22010-06-08 16:52:24 +0000174 if (level == lldb::eDescriptionLevelFull)
175 {
176 if (is_start_of_statement)
177 *s << ", is_start_of_statement = TRUE";
178
179 if (is_start_of_basic_block)
180 *s << ", is_start_of_basic_block = TRUE";
181
182 if (is_prologue_end)
183 *s << ", is_prologue_end = TRUE";
184
185 if (is_epilogue_begin)
186 *s << ", is_epilogue_begin = TRUE";
187
188 if (is_terminal_entry)
189 *s << ", is_terminal_entry = TRUE";
190 }
191 else
192 {
193 if (is_terminal_entry)
194 s->EOL();
195 }
196 }
197 else
198 {
Greg Claytoneea26402010-09-14 23:36:40 +0000199 return Dump (s, target, true, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000200 }
201 return true;
202}
203
204
205bool
206lldb_private::operator< (const LineEntry& a, const LineEntry& b)
207{
208 return LineEntry::Compare (a, b) < 0;
209}
210
211int
212LineEntry::Compare (const LineEntry& a, const LineEntry& b)
213{
214 int result = Address::CompareFileAddress (a.range.GetBaseAddress(), b.range.GetBaseAddress());
215 if (result != 0)
216 return result;
217
218 const lldb::addr_t a_byte_size = a.range.GetByteSize();
219 const lldb::addr_t b_byte_size = b.range.GetByteSize();
220
221 if (a_byte_size < b_byte_size)
222 return -1;
223 if (a_byte_size > b_byte_size)
224 return +1;
225
226 // Check for an end sequence entry mismatch after we have determined
227 // that the address values are equal. If one of the items is an end
228 // sequence, we don't care about the line, file, or column info.
229 if (a.is_terminal_entry > b.is_terminal_entry)
230 return -1;
231 if (a.is_terminal_entry < b.is_terminal_entry)
232 return +1;
233
234 if (a.line < b.line)
235 return -1;
236 if (a.line > b.line)
237 return +1;
238
239 if (a.column < b.column)
240 return -1;
241 if (a.column > b.column)
242 return +1;
243
244 return FileSpec::Compare (a.file, b.file, true);
245}
246