Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 1 | //===-- UnwindPlan.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/UnwindPlan.h" |
Greg Clayton | 79ea878 | 2011-04-26 23:48:45 +0000 | [diff] [blame] | 11 | |
| 12 | #include "lldb/Core/ConstString.h" |
Jason Molenda | 61cd072 | 2013-12-03 04:46:27 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Log.h" |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 14 | #include "lldb/Target/Process.h" |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 15 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 16 | #include "lldb/Target/Thread.h" |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
| 21 | bool |
| 22 | UnwindPlan::Row::RegisterLocation::operator == (const UnwindPlan::Row::RegisterLocation& rhs) const |
| 23 | { |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 24 | if (m_type == rhs.m_type) |
| 25 | { |
| 26 | switch (m_type) |
| 27 | { |
| 28 | case unspecified: |
| 29 | case undefined: |
| 30 | case same: |
| 31 | return true; |
| 32 | |
| 33 | case atCFAPlusOffset: |
| 34 | case isCFAPlusOffset: |
| 35 | return m_location.offset == rhs.m_location.offset; |
| 36 | |
| 37 | case inOtherRegister: |
| 38 | return m_location.reg_num == rhs.m_location.reg_num; |
| 39 | |
| 40 | case atDWARFExpression: |
| 41 | case isDWARFExpression: |
| 42 | if (m_location.expr.length == rhs.m_location.expr.length) |
| 43 | return !memcmp (m_location.expr.opcodes, rhs.m_location.expr.opcodes, m_location.expr.length); |
| 44 | break; |
| 45 | } |
| 46 | } |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 47 | return false; |
| 48 | } |
| 49 | |
| 50 | // This function doesn't copy the dwarf expression bytes; they must remain in allocated |
| 51 | // memory for the lifespan of this UnwindPlan object. |
| 52 | void |
| 53 | UnwindPlan::Row::RegisterLocation::SetAtDWARFExpression (const uint8_t *opcodes, uint32_t len) |
| 54 | { |
| 55 | m_type = atDWARFExpression; |
| 56 | m_location.expr.opcodes = opcodes; |
| 57 | m_location.expr.length = len; |
| 58 | } |
| 59 | |
| 60 | // This function doesn't copy the dwarf expression bytes; they must remain in allocated |
| 61 | // memory for the lifespan of this UnwindPlan object. |
| 62 | void |
| 63 | UnwindPlan::Row::RegisterLocation::SetIsDWARFExpression (const uint8_t *opcodes, uint32_t len) |
| 64 | { |
| 65 | m_type = isDWARFExpression; |
| 66 | m_location.expr.opcodes = opcodes; |
| 67 | m_location.expr.length = len; |
| 68 | } |
| 69 | |
| 70 | void |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 71 | UnwindPlan::Row::RegisterLocation::Dump (Stream &s, const UnwindPlan* unwind_plan, const UnwindPlan::Row* row, Thread* thread, bool verbose) const |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 72 | { |
| 73 | switch (m_type) |
| 74 | { |
| 75 | case unspecified: |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 76 | if (verbose) |
| 77 | s.PutCString ("=<unspec>"); |
| 78 | else |
| 79 | s.PutCString ("=!"); |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 80 | break; |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 81 | case undefined: |
| 82 | if (verbose) |
| 83 | s.PutCString ("=<undef>"); |
| 84 | else |
| 85 | s.PutCString ("=?"); |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 86 | break; |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 87 | case same: |
| 88 | s.PutCString ("= <same>"); |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 89 | break; |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 90 | |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 91 | case atCFAPlusOffset: |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 92 | case isCFAPlusOffset: |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 93 | { |
| 94 | s.PutChar('='); |
| 95 | if (m_type == atCFAPlusOffset) |
| 96 | s.PutChar('['); |
| 97 | if (verbose) |
| 98 | s.Printf ("CFA%+d", m_location.offset); |
| 99 | |
| 100 | if (unwind_plan && row) |
| 101 | { |
| 102 | const uint32_t cfa_reg = row->GetCFARegister(); |
| 103 | const RegisterInfo *cfa_reg_info = unwind_plan->GetRegisterInfo (thread, cfa_reg); |
| 104 | const int32_t offset = row->GetCFAOffset() + m_location.offset; |
| 105 | if (verbose) |
| 106 | { |
| 107 | if (cfa_reg_info) |
| 108 | s.Printf (" (%s%+d)", cfa_reg_info->name, offset); |
| 109 | else |
Johnny Chen | d397dc8 | 2011-08-12 00:02:24 +0000 | [diff] [blame] | 110 | s.Printf (" (reg(%u)%+d)", cfa_reg, offset); |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 111 | } |
| 112 | else |
| 113 | { |
| 114 | if (cfa_reg_info) |
| 115 | s.Printf ("%s", cfa_reg_info->name); |
| 116 | else |
Johnny Chen | d397dc8 | 2011-08-12 00:02:24 +0000 | [diff] [blame] | 117 | s.Printf ("reg(%u)", cfa_reg); |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 118 | if (offset != 0) |
| 119 | s.Printf ("%+d", offset); |
| 120 | } |
| 121 | } |
| 122 | if (m_type == atCFAPlusOffset) |
| 123 | s.PutChar(']'); |
| 124 | } |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 125 | break; |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 126 | |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 127 | case inOtherRegister: |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 128 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 129 | const RegisterInfo *other_reg_info = nullptr; |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 130 | if (unwind_plan) |
| 131 | other_reg_info = unwind_plan->GetRegisterInfo (thread, m_location.reg_num); |
| 132 | if (other_reg_info) |
| 133 | s.Printf ("=%s", other_reg_info->name); |
| 134 | else |
| 135 | s.Printf ("=reg(%u)", m_location.reg_num); |
| 136 | } |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 137 | break; |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 138 | |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 139 | case atDWARFExpression: |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 140 | case isDWARFExpression: |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 141 | { |
| 142 | s.PutChar('='); |
| 143 | if (m_type == atDWARFExpression) |
| 144 | s.PutCString("[dwarf-expr]"); |
| 145 | else |
| 146 | s.PutCString("dwarf-expr"); |
| 147 | } |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 148 | break; |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 149 | |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
| 153 | void |
| 154 | UnwindPlan::Row::Clear () |
| 155 | { |
| 156 | m_offset = 0; |
Jason Molenda | 60f0bd4 | 2012-10-26 06:08:58 +0000 | [diff] [blame] | 157 | m_cfa_reg_num = LLDB_INVALID_REGNUM; |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 158 | m_cfa_offset = 0; |
| 159 | m_register_locations.clear(); |
| 160 | } |
| 161 | |
| 162 | void |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 163 | UnwindPlan::Row::Dump (Stream& s, const UnwindPlan* unwind_plan, Thread* thread, addr_t base_addr) const |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 164 | { |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 165 | const RegisterInfo *reg_info = unwind_plan->GetRegisterInfo (thread, GetCFARegister()); |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 166 | |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 167 | if (base_addr != LLDB_INVALID_ADDRESS) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 168 | s.Printf ("0x%16.16" PRIx64 ": CFA=", base_addr + GetOffset()); |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 169 | else |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 170 | s.Printf ("0x%8.8" PRIx64 ": CFA=", GetOffset()); |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 171 | |
| 172 | if (reg_info) |
| 173 | s.Printf ("%s", reg_info->name); |
| 174 | else |
| 175 | s.Printf ("reg(%u)", GetCFARegister()); |
Jason Molenda | 4210713 | 2012-08-10 20:52:59 +0000 | [diff] [blame] | 176 | s.Printf ("%+3d => ", GetCFAOffset ()); |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 177 | for (collection::const_iterator idx = m_register_locations.begin (); idx != m_register_locations.end (); ++idx) |
| 178 | { |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 179 | reg_info = unwind_plan->GetRegisterInfo (thread, idx->first); |
| 180 | if (reg_info) |
| 181 | s.Printf ("%s", reg_info->name); |
| 182 | else |
| 183 | s.Printf ("reg(%u)", idx->first); |
| 184 | const bool verbose = false; |
| 185 | idx->second.Dump(s, unwind_plan, this, thread, verbose); |
| 186 | s.PutChar (' '); |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 187 | } |
Greg Clayton | 877aaa5 | 2011-01-08 21:19:00 +0000 | [diff] [blame] | 188 | s.EOL(); |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | UnwindPlan::Row::Row() : |
| 192 | m_offset(0), |
Jason Molenda | 60f0bd4 | 2012-10-26 06:08:58 +0000 | [diff] [blame] | 193 | m_cfa_reg_num(LLDB_INVALID_REGNUM), |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 194 | m_cfa_offset(0), |
| 195 | m_register_locations() |
| 196 | { |
| 197 | } |
| 198 | |
| 199 | bool |
| 200 | UnwindPlan::Row::GetRegisterInfo (uint32_t reg_num, UnwindPlan::Row::RegisterLocation& register_location) const |
| 201 | { |
| 202 | collection::const_iterator pos = m_register_locations.find(reg_num); |
| 203 | if (pos != m_register_locations.end()) |
| 204 | { |
| 205 | register_location = pos->second; |
| 206 | return true; |
| 207 | } |
| 208 | return false; |
| 209 | } |
| 210 | |
| 211 | void |
| 212 | UnwindPlan::Row::SetRegisterInfo (uint32_t reg_num, const UnwindPlan::Row::RegisterLocation register_location) |
| 213 | { |
| 214 | m_register_locations[reg_num] = register_location; |
| 215 | } |
| 216 | |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 217 | bool |
| 218 | UnwindPlan::Row::SetRegisterLocationToAtCFAPlusOffset (uint32_t reg_num, int32_t offset, bool can_replace) |
| 219 | { |
| 220 | if (!can_replace && m_register_locations.find(reg_num) != m_register_locations.end()) |
| 221 | return false; |
| 222 | RegisterLocation reg_loc; |
| 223 | reg_loc.SetAtCFAPlusOffset(offset); |
| 224 | m_register_locations[reg_num] = reg_loc; |
| 225 | return true; |
| 226 | } |
| 227 | |
| 228 | bool |
| 229 | UnwindPlan::Row::SetRegisterLocationToIsCFAPlusOffset (uint32_t reg_num, int32_t offset, bool can_replace) |
| 230 | { |
| 231 | if (!can_replace && m_register_locations.find(reg_num) != m_register_locations.end()) |
| 232 | return false; |
| 233 | RegisterLocation reg_loc; |
| 234 | reg_loc.SetIsCFAPlusOffset(offset); |
| 235 | m_register_locations[reg_num] = reg_loc; |
| 236 | return true; |
| 237 | } |
| 238 | |
| 239 | bool |
| 240 | UnwindPlan::Row::SetRegisterLocationToUndefined (uint32_t reg_num, bool can_replace, bool can_replace_only_if_unspecified) |
| 241 | { |
| 242 | collection::iterator pos = m_register_locations.find(reg_num); |
| 243 | collection::iterator end = m_register_locations.end(); |
| 244 | |
| 245 | if (pos != end) |
| 246 | { |
| 247 | if (!can_replace) |
| 248 | return false; |
| 249 | if (can_replace_only_if_unspecified && !pos->second.IsUnspecified()) |
| 250 | return false; |
| 251 | } |
| 252 | RegisterLocation reg_loc; |
| 253 | reg_loc.SetUndefined(); |
| 254 | m_register_locations[reg_num] = reg_loc; |
| 255 | return true; |
| 256 | } |
| 257 | |
| 258 | bool |
| 259 | UnwindPlan::Row::SetRegisterLocationToUnspecified (uint32_t reg_num, bool can_replace) |
| 260 | { |
| 261 | if (!can_replace && m_register_locations.find(reg_num) != m_register_locations.end()) |
| 262 | return false; |
| 263 | RegisterLocation reg_loc; |
| 264 | reg_loc.SetUnspecified(); |
| 265 | m_register_locations[reg_num] = reg_loc; |
| 266 | return true; |
| 267 | } |
| 268 | |
| 269 | bool |
| 270 | UnwindPlan::Row::SetRegisterLocationToRegister (uint32_t reg_num, |
| 271 | uint32_t other_reg_num, |
| 272 | bool can_replace) |
| 273 | { |
| 274 | if (!can_replace && m_register_locations.find(reg_num) != m_register_locations.end()) |
| 275 | return false; |
| 276 | RegisterLocation reg_loc; |
| 277 | reg_loc.SetInRegister(other_reg_num); |
| 278 | m_register_locations[reg_num] = reg_loc; |
| 279 | return true; |
| 280 | } |
| 281 | |
| 282 | bool |
| 283 | UnwindPlan::Row::SetRegisterLocationToSame (uint32_t reg_num, bool must_replace) |
| 284 | { |
| 285 | if (must_replace && m_register_locations.find(reg_num) == m_register_locations.end()) |
| 286 | return false; |
| 287 | RegisterLocation reg_loc; |
| 288 | reg_loc.SetSame(); |
| 289 | m_register_locations[reg_num] = reg_loc; |
| 290 | return true; |
| 291 | } |
| 292 | |
| 293 | void |
| 294 | UnwindPlan::Row::SetCFARegister (uint32_t reg_num) |
| 295 | { |
| 296 | m_cfa_reg_num = reg_num; |
| 297 | } |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 298 | |
Jason Molenda | 24a8378 | 2012-07-17 01:57:24 +0000 | [diff] [blame] | 299 | bool |
| 300 | UnwindPlan::Row::operator == (const UnwindPlan::Row& rhs) const |
| 301 | { |
| 302 | if (m_offset != rhs.m_offset || m_cfa_reg_num != rhs.m_cfa_reg_num || m_cfa_offset != rhs.m_cfa_offset) |
| 303 | return false; |
Greg Clayton | 358a789 | 2012-07-18 20:37:53 +0000 | [diff] [blame] | 304 | return m_register_locations == rhs.m_register_locations; |
Jason Molenda | 24a8378 | 2012-07-17 01:57:24 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 307 | void |
Greg Clayton | 358a789 | 2012-07-18 20:37:53 +0000 | [diff] [blame] | 308 | UnwindPlan::AppendRow (const UnwindPlan::RowSP &row_sp) |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 309 | { |
Greg Clayton | 358a789 | 2012-07-18 20:37:53 +0000 | [diff] [blame] | 310 | if (m_row_list.empty() || m_row_list.back()->GetOffset() != row_sp->GetOffset()) |
| 311 | m_row_list.push_back(row_sp); |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 312 | else |
Greg Clayton | 358a789 | 2012-07-18 20:37:53 +0000 | [diff] [blame] | 313 | m_row_list.back() = row_sp; |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Todd Fiala | 0562524 | 2014-08-25 20:29:09 +0000 | [diff] [blame^] | 316 | void |
| 317 | UnwindPlan::InsertRow (const UnwindPlan::RowSP &row_sp) |
| 318 | { |
| 319 | collection::iterator it = m_row_list.begin(); |
| 320 | while (it != m_row_list.end()) { |
| 321 | RowSP row = *it; |
| 322 | if (row->GetOffset() > row_sp->GetOffset()) |
| 323 | break; |
| 324 | it++; |
| 325 | } |
| 326 | m_row_list.insert(it, row_sp); |
| 327 | } |
| 328 | |
Jason Molenda | 1d42c7b | 2012-07-14 04:52:53 +0000 | [diff] [blame] | 329 | UnwindPlan::RowSP |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 330 | UnwindPlan::GetRowForFunctionOffset (int offset) const |
| 331 | { |
Jason Molenda | 1d42c7b | 2012-07-14 04:52:53 +0000 | [diff] [blame] | 332 | RowSP row; |
Greg Clayton | 877aaa5 | 2011-01-08 21:19:00 +0000 | [diff] [blame] | 333 | if (!m_row_list.empty()) |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 334 | { |
Greg Clayton | 877aaa5 | 2011-01-08 21:19:00 +0000 | [diff] [blame] | 335 | if (offset == -1) |
Jason Molenda | 1d42c7b | 2012-07-14 04:52:53 +0000 | [diff] [blame] | 336 | row = m_row_list.back(); |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 337 | else |
| 338 | { |
Greg Clayton | 877aaa5 | 2011-01-08 21:19:00 +0000 | [diff] [blame] | 339 | collection::const_iterator pos, end = m_row_list.end(); |
| 340 | for (pos = m_row_list.begin(); pos != end; ++pos) |
| 341 | { |
Saleem Abdulrasool | 3985c8c | 2014-04-02 03:51:35 +0000 | [diff] [blame] | 342 | if ((*pos)->GetOffset() <= static_cast<lldb::offset_t>(offset)) |
Jason Molenda | 1d42c7b | 2012-07-14 04:52:53 +0000 | [diff] [blame] | 343 | row = *pos; |
Greg Clayton | 877aaa5 | 2011-01-08 21:19:00 +0000 | [diff] [blame] | 344 | else |
| 345 | break; |
| 346 | } |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 347 | } |
| 348 | } |
Jason Molenda | 1d42c7b | 2012-07-14 04:52:53 +0000 | [diff] [blame] | 349 | return row; |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | bool |
| 353 | UnwindPlan::IsValidRowIndex (uint32_t idx) const |
| 354 | { |
| 355 | return idx < m_row_list.size(); |
| 356 | } |
| 357 | |
Jason Molenda | 1d42c7b | 2012-07-14 04:52:53 +0000 | [diff] [blame] | 358 | const UnwindPlan::RowSP |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 359 | UnwindPlan::GetRowAtIndex (uint32_t idx) const |
| 360 | { |
| 361 | // You must call IsValidRowIndex(idx) first before calling this!!! |
Greg Clayton | 877aaa5 | 2011-01-08 21:19:00 +0000 | [diff] [blame] | 362 | assert (idx < m_row_list.size()); |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 363 | return m_row_list[idx]; |
| 364 | } |
| 365 | |
Jason Molenda | 1d42c7b | 2012-07-14 04:52:53 +0000 | [diff] [blame] | 366 | const UnwindPlan::RowSP |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 367 | UnwindPlan::GetLastRow () const |
| 368 | { |
| 369 | // You must call GetRowCount() first to make sure there is at least one row |
| 370 | assert (!m_row_list.empty()); |
| 371 | return m_row_list.back(); |
| 372 | } |
| 373 | |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 374 | int |
| 375 | UnwindPlan::GetRowCount () const |
| 376 | { |
| 377 | return m_row_list.size (); |
| 378 | } |
| 379 | |
| 380 | void |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 381 | UnwindPlan::SetPlanValidAddressRange (const AddressRange& range) |
| 382 | { |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 383 | if (range.GetBaseAddress().IsValid() && range.GetByteSize() != 0) |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 384 | m_plan_valid_address_range = range; |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | bool |
| 388 | UnwindPlan::PlanValidAtAddress (Address addr) |
| 389 | { |
Jason Molenda | 61cd072 | 2013-12-03 04:46:27 +0000 | [diff] [blame] | 390 | // If this UnwindPlan has no rows, it is an invalid UnwindPlan. |
| 391 | if (GetRowCount() == 0) |
| 392 | { |
| 393 | Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); |
| 394 | if (log) |
Jason Molenda | 135e55f | 2013-12-03 21:59:39 +0000 | [diff] [blame] | 395 | { |
| 396 | StreamString s; |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 397 | if (addr.Dump (&s, nullptr, Address::DumpStyleSectionNameOffset)) |
Jason Molenda | 135e55f | 2013-12-03 21:59:39 +0000 | [diff] [blame] | 398 | { |
| 399 | log->Printf ("UnwindPlan is invalid -- no unwind rows for UnwindPlan '%s' at address %s", |
| 400 | m_source_name.GetCString(), s.GetData()); |
| 401 | } |
| 402 | else |
| 403 | { |
| 404 | log->Printf ("UnwindPlan is invalid -- no unwind rows for UnwindPlan '%s'", |
| 405 | m_source_name.GetCString()); |
| 406 | } |
| 407 | } |
Jason Molenda | 61cd072 | 2013-12-03 04:46:27 +0000 | [diff] [blame] | 408 | return false; |
| 409 | } |
| 410 | |
| 411 | // If the 0th Row of unwind instructions is missing, or if it doesn't provide |
| 412 | // a register to use to find the Canonical Frame Address, this is not a valid UnwindPlan. |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 413 | if (GetRowAtIndex(0).get() == nullptr || GetRowAtIndex(0)->GetCFARegister() == LLDB_INVALID_REGNUM) |
Jason Molenda | 61cd072 | 2013-12-03 04:46:27 +0000 | [diff] [blame] | 414 | { |
| 415 | Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); |
| 416 | if (log) |
Jason Molenda | 135e55f | 2013-12-03 21:59:39 +0000 | [diff] [blame] | 417 | { |
| 418 | StreamString s; |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 419 | if (addr.Dump (&s, nullptr, Address::DumpStyleSectionNameOffset)) |
Jason Molenda | 135e55f | 2013-12-03 21:59:39 +0000 | [diff] [blame] | 420 | { |
| 421 | log->Printf ("UnwindPlan is invalid -- no CFA register defined in row 0 for UnwindPlan '%s' at address %s", |
| 422 | m_source_name.GetCString(), s.GetData()); |
| 423 | } |
| 424 | else |
| 425 | { |
| 426 | log->Printf ("UnwindPlan is invalid -- no CFA register defined in row 0 for UnwindPlan '%s'", |
| 427 | m_source_name.GetCString()); |
| 428 | } |
| 429 | } |
Jason Molenda | 61cd072 | 2013-12-03 04:46:27 +0000 | [diff] [blame] | 430 | return false; |
| 431 | } |
| 432 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 433 | if (!m_plan_valid_address_range.GetBaseAddress().IsValid() || m_plan_valid_address_range.GetByteSize() == 0) |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 434 | return true; |
| 435 | |
Jason Molenda | 5976200 | 2010-11-04 00:53:20 +0000 | [diff] [blame] | 436 | if (!addr.IsValid()) |
| 437 | return true; |
| 438 | |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 439 | if (m_plan_valid_address_range.ContainsFileAddress (addr)) |
| 440 | return true; |
| 441 | |
| 442 | return false; |
| 443 | } |
| 444 | |
| 445 | void |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 446 | UnwindPlan::Dump (Stream& s, Thread *thread, lldb::addr_t base_addr) const |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 447 | { |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 448 | if (!m_source_name.IsEmpty()) |
| 449 | { |
| 450 | s.Printf ("This UnwindPlan originally sourced from %s\n", m_source_name.GetCString()); |
| 451 | } |
| 452 | if (m_plan_valid_address_range.GetBaseAddress().IsValid() && m_plan_valid_address_range.GetByteSize() > 0) |
| 453 | { |
Greg Clayton | 877aaa5 | 2011-01-08 21:19:00 +0000 | [diff] [blame] | 454 | s.PutCString ("Address range of this UnwindPlan: "); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 455 | TargetSP target_sp(thread->CalculateTarget()); |
| 456 | m_plan_valid_address_range.Dump (&s, target_sp.get(), Address::DumpStyleSectionNameOffset); |
Greg Clayton | 877aaa5 | 2011-01-08 21:19:00 +0000 | [diff] [blame] | 457 | s.EOL(); |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 458 | } |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 459 | collection::const_iterator pos, begin = m_row_list.begin(), end = m_row_list.end(); |
| 460 | for (pos = begin; pos != end; ++pos) |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 461 | { |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 462 | s.Printf ("row[%u]: ", (uint32_t)std::distance (begin, pos)); |
Jason Molenda | 1d42c7b | 2012-07-14 04:52:53 +0000 | [diff] [blame] | 463 | (*pos)->Dump(s, this, thread, base_addr); |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 464 | } |
| 465 | } |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 466 | |
| 467 | void |
| 468 | UnwindPlan::SetSourceName (const char *source) |
| 469 | { |
| 470 | m_source_name = ConstString (source); |
| 471 | } |
| 472 | |
| 473 | ConstString |
| 474 | UnwindPlan::GetSourceName () const |
| 475 | { |
| 476 | return m_source_name; |
| 477 | } |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 478 | |
| 479 | const RegisterInfo * |
| 480 | UnwindPlan::GetRegisterInfo (Thread* thread, uint32_t unwind_reg) const |
| 481 | { |
| 482 | if (thread) |
| 483 | { |
| 484 | RegisterContext *reg_ctx = thread->GetRegisterContext().get(); |
| 485 | if (reg_ctx) |
| 486 | { |
| 487 | uint32_t reg; |
| 488 | if (m_register_kind == eRegisterKindLLDB) |
| 489 | reg = unwind_reg; |
| 490 | else |
| 491 | reg = reg_ctx->ConvertRegisterKindToRegisterNumber (m_register_kind, unwind_reg); |
| 492 | if (reg != LLDB_INVALID_REGNUM) |
| 493 | return reg_ctx->GetRegisterInfoAtIndex (reg); |
| 494 | } |
| 495 | } |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 496 | return nullptr; |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 497 | } |
| 498 | |