Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBLineEntry.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 | |
Stephen Wilson | ec2d978 | 2011-04-08 13:36:44 +0000 | [diff] [blame] | 10 | #include <limits.h> |
| 11 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBLineEntry.h" |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 13 | #include "lldb/API/SBStream.h" |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 14 | #include "lldb/Core/StreamString.h" |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Log.h" |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 16 | #include "lldb/Symbol/LineEntry.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace lldb; |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 19 | using namespace lldb_private; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | |
| 21 | |
| 22 | SBLineEntry::SBLineEntry () : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 23 | m_opaque_ap () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | { |
| 25 | } |
| 26 | |
| 27 | SBLineEntry::SBLineEntry (const SBLineEntry &rhs) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 28 | m_opaque_ap () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | { |
| 30 | if (rhs.IsValid()) |
Greg Clayton | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 31 | ref() = rhs.ref(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | SBLineEntry::SBLineEntry (const lldb_private::LineEntry *lldb_object_ptr) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 35 | m_opaque_ap () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | { |
| 37 | if (lldb_object_ptr) |
Greg Clayton | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 38 | ref() = *lldb_object_ptr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | const SBLineEntry & |
| 42 | SBLineEntry::operator = (const SBLineEntry &rhs) |
| 43 | { |
Greg Clayton | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 44 | if (this != &rhs) |
| 45 | { |
| 46 | if (rhs.IsValid()) |
| 47 | ref() = rhs.ref(); |
| 48 | else |
| 49 | m_opaque_ap.reset(); |
| 50 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | return *this; |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | SBLineEntry::SetLineEntry (const lldb_private::LineEntry &lldb_object_ref) |
| 56 | { |
Greg Clayton | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 57 | ref() = lldb_object_ref; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | |
| 61 | SBLineEntry::~SBLineEntry () |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | |
| 66 | SBAddress |
| 67 | SBLineEntry::GetStartAddress () const |
| 68 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 69 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 70 | SBAddress sb_address; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 71 | if (m_opaque_ap.get()) |
| 72 | sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 73 | |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame^] | 74 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 75 | if (log) |
| 76 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 77 | StreamString sstr; |
Greg Clayton | 69c540d | 2012-04-04 20:36:48 +0000 | [diff] [blame] | 78 | const Address *addr = sb_address.get(); |
| 79 | if (addr) |
| 80 | addr->Dump (&sstr, NULL, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleInvalid, 4); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 81 | log->Printf ("SBLineEntry(%p)::GetStartAddress () => SBAddress (%p): %s", |
| 82 | m_opaque_ap.get(), sb_address.get(), sstr.GetData()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 85 | return sb_address; |
| 86 | } |
| 87 | |
| 88 | SBAddress |
| 89 | SBLineEntry::GetEndAddress () const |
| 90 | { |
| 91 | SBAddress sb_address; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 92 | if (m_opaque_ap.get()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 93 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 94 | sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress()); |
| 95 | sb_address.OffsetAddress(m_opaque_ap->range.GetByteSize()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 96 | } |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame^] | 97 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 98 | if (log) |
| 99 | { |
| 100 | StreamString sstr; |
Greg Clayton | 69c540d | 2012-04-04 20:36:48 +0000 | [diff] [blame] | 101 | const Address *addr = sb_address.get(); |
| 102 | if (addr) |
| 103 | addr->Dump (&sstr, NULL, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleInvalid, 4); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 104 | log->Printf ("SBLineEntry(%p)::GetEndAddress () => SBAddress (%p): %s", |
| 105 | m_opaque_ap.get(), sb_address.get(), sstr.GetData()); |
| 106 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 107 | return sb_address; |
| 108 | } |
| 109 | |
| 110 | bool |
| 111 | SBLineEntry::IsValid () const |
| 112 | { |
Greg Clayton | 3a70d5d | 2012-06-27 20:18:01 +0000 | [diff] [blame] | 113 | return m_opaque_ap.get() && m_opaque_ap->IsValid(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | |
| 117 | SBFileSpec |
| 118 | SBLineEntry::GetFileSpec () const |
| 119 | { |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame^] | 120 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 121 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 122 | SBFileSpec sb_file_spec; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 123 | if (m_opaque_ap.get() && m_opaque_ap->file) |
| 124 | sb_file_spec.SetFileSpec(m_opaque_ap->file); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 125 | |
| 126 | if (log) |
| 127 | { |
| 128 | SBStream sstr; |
| 129 | sb_file_spec.GetDescription (sstr); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 130 | log->Printf ("SBLineEntry(%p)::GetFileSpec () => SBFileSpec(%p): %s", m_opaque_ap.get(), |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 131 | sb_file_spec.get(), sstr.GetData()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 134 | return sb_file_spec; |
| 135 | } |
| 136 | |
| 137 | uint32_t |
| 138 | SBLineEntry::GetLine () const |
| 139 | { |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame^] | 140 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 141 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 142 | uint32_t line = 0; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 143 | if (m_opaque_ap.get()) |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 144 | line = m_opaque_ap->line; |
| 145 | |
| 146 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 147 | log->Printf ("SBLineEntry(%p)::GetLine () => %u", m_opaque_ap.get(), line); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 148 | |
| 149 | return line; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | |
| 153 | uint32_t |
| 154 | SBLineEntry::GetColumn () const |
| 155 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 156 | if (m_opaque_ap.get()) |
| 157 | return m_opaque_ap->column; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 158 | return 0; |
| 159 | } |
| 160 | |
Greg Clayton | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 161 | void |
| 162 | SBLineEntry::SetFileSpec (lldb::SBFileSpec filespec) |
| 163 | { |
| 164 | if (filespec.IsValid()) |
| 165 | ref().file = filespec.ref(); |
| 166 | else |
| 167 | ref().file.Clear(); |
| 168 | } |
| 169 | void |
| 170 | SBLineEntry::SetLine (uint32_t line) |
| 171 | { |
| 172 | ref().line = line; |
| 173 | } |
| 174 | |
| 175 | void |
| 176 | SBLineEntry::SetColumn (uint32_t column) |
| 177 | { |
| 178 | ref().line = column; |
| 179 | } |
| 180 | |
| 181 | |
| 182 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 183 | bool |
| 184 | SBLineEntry::operator == (const SBLineEntry &rhs) const |
| 185 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 186 | lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get(); |
| 187 | lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 188 | |
| 189 | if (lhs_ptr && rhs_ptr) |
| 190 | return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) == 0; |
| 191 | |
| 192 | return lhs_ptr == rhs_ptr; |
| 193 | } |
| 194 | |
| 195 | bool |
| 196 | SBLineEntry::operator != (const SBLineEntry &rhs) const |
| 197 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 198 | lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get(); |
| 199 | lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 200 | |
| 201 | if (lhs_ptr && rhs_ptr) |
| 202 | return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) != 0; |
| 203 | |
| 204 | return lhs_ptr != rhs_ptr; |
| 205 | } |
| 206 | |
| 207 | const lldb_private::LineEntry * |
| 208 | SBLineEntry::operator->() const |
| 209 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 210 | return m_opaque_ap.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Greg Clayton | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 213 | lldb_private::LineEntry & |
| 214 | SBLineEntry::ref() |
| 215 | { |
| 216 | if (m_opaque_ap.get() == NULL) |
| 217 | m_opaque_ap.reset (new lldb_private::LineEntry ()); |
| 218 | return *m_opaque_ap; |
| 219 | } |
| 220 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 221 | const lldb_private::LineEntry & |
Greg Clayton | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 222 | SBLineEntry::ref() const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 223 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 224 | return *m_opaque_ap; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 227 | bool |
| 228 | SBLineEntry::GetDescription (SBStream &description) |
| 229 | { |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 230 | Stream &strm = description.ref(); |
| 231 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 232 | if (m_opaque_ap.get()) |
| 233 | { |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 234 | char file_path[PATH_MAX*2]; |
| 235 | m_opaque_ap->file.GetPath (file_path, sizeof (file_path)); |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 236 | strm.Printf ("%s:%u", file_path, GetLine()); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 237 | if (GetColumn() > 0) |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 238 | strm.Printf (":%u", GetColumn()); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 239 | } |
| 240 | else |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 241 | strm.PutCString ("No value"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 242 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 243 | return true; |
| 244 | } |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 245 | |
| 246 | lldb_private::LineEntry * |
| 247 | SBLineEntry::get () |
| 248 | { |
| 249 | return m_opaque_ap.get(); |
| 250 | } |