Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBTarget.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 | |
Daniel Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Eli Friedman | 4c5de69 | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBTarget.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 14 | #include "lldb/lldb-public.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 16 | #include "lldb/API/SBDebugger.h" |
| 17 | #include "lldb/API/SBBreakpoint.h" |
Greg Clayton | 4b63a5c | 2013-01-04 18:10:18 +0000 | [diff] [blame] | 18 | #include "lldb/API/SBExpressionOptions.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/API/SBFileSpec.h" |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 20 | #include "lldb/API/SBListener.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/API/SBModule.h" |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame^] | 22 | #include "lldb/API/SBModuleSpec.h" |
Jim Ingham | e37d605 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 23 | #include "lldb/API/SBSourceManager.h" |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 24 | #include "lldb/API/SBProcess.h" |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 25 | #include "lldb/API/SBStream.h" |
Greg Clayton | fe356d3 | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 26 | #include "lldb/API/SBSymbolContextList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | #include "lldb/Breakpoint/BreakpointID.h" |
| 28 | #include "lldb/Breakpoint/BreakpointIDList.h" |
| 29 | #include "lldb/Breakpoint/BreakpointList.h" |
| 30 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 31 | #include "lldb/Core/Address.h" |
| 32 | #include "lldb/Core/AddressResolver.h" |
| 33 | #include "lldb/Core/AddressResolverName.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | #include "lldb/Core/ArchSpec.h" |
| 35 | #include "lldb/Core/Debugger.h" |
| 36 | #include "lldb/Core/Disassembler.h" |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 37 | #include "lldb/Core/Log.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 38 | #include "lldb/Core/Module.h" |
| 39 | #include "lldb/Core/ModuleSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | #include "lldb/Core/RegularExpression.h" |
| 41 | #include "lldb/Core/SearchFilter.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 42 | #include "lldb/Core/Section.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | #include "lldb/Core/STLUtils.h" |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 44 | #include "lldb/Core/ValueObjectList.h" |
| 45 | #include "lldb/Core/ValueObjectVariable.h" |
| 46 | #include "lldb/Host/FileSpec.h" |
Greg Clayton | 7fb56d0 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 47 | #include "lldb/Host/Host.h" |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 48 | #include "lldb/Interpreter/Args.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 49 | #include "lldb/Symbol/ObjectFile.h" |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 50 | #include "lldb/Symbol/SymbolVendor.h" |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 51 | #include "lldb/Symbol/VariableList.h" |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 52 | #include "lldb/Target/LanguageRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | #include "lldb/Target/Process.h" |
| 54 | #include "lldb/Target/Target.h" |
| 55 | #include "lldb/Target/TargetList.h" |
| 56 | |
| 57 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 58 | #include "../source/Commands/CommandObjectBreakpoint.h" |
| 59 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | |
| 61 | using namespace lldb; |
| 62 | using namespace lldb_private; |
| 63 | |
| 64 | #define DEFAULT_DISASM_BYTE_SIZE 32 |
| 65 | |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 66 | SBLaunchInfo::SBLaunchInfo (const char **argv) : |
| 67 | m_opaque_sp(new ProcessLaunchInfo()) |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 68 | { |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 69 | m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR); |
| 70 | if (argv && argv[0]) |
| 71 | m_opaque_sp->GetArguments().SetArguments(argv); |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Greg Clayton | ecc7c0d | 2012-03-07 23:52:51 +0000 | [diff] [blame] | 74 | SBLaunchInfo::~SBLaunchInfo() |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | lldb_private::ProcessLaunchInfo & |
| 79 | SBLaunchInfo::ref () |
| 80 | { |
| 81 | return *m_opaque_sp; |
| 82 | } |
| 83 | |
| 84 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 85 | uint32_t |
| 86 | SBLaunchInfo::GetUserID() |
| 87 | { |
| 88 | return m_opaque_sp->GetUserID(); |
| 89 | } |
| 90 | |
| 91 | uint32_t |
| 92 | SBLaunchInfo::GetGroupID() |
| 93 | { |
| 94 | return m_opaque_sp->GetGroupID(); |
| 95 | } |
| 96 | |
| 97 | bool |
| 98 | SBLaunchInfo::UserIDIsValid () |
| 99 | { |
| 100 | return m_opaque_sp->UserIDIsValid(); |
| 101 | } |
| 102 | |
| 103 | bool |
| 104 | SBLaunchInfo::GroupIDIsValid () |
| 105 | { |
| 106 | return m_opaque_sp->GroupIDIsValid(); |
| 107 | } |
| 108 | |
| 109 | void |
| 110 | SBLaunchInfo::SetUserID (uint32_t uid) |
| 111 | { |
| 112 | m_opaque_sp->SetUserID (uid); |
| 113 | } |
| 114 | |
| 115 | void |
| 116 | SBLaunchInfo::SetGroupID (uint32_t gid) |
| 117 | { |
| 118 | m_opaque_sp->SetGroupID (gid); |
| 119 | } |
| 120 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 121 | uint32_t |
| 122 | SBLaunchInfo::GetNumArguments () |
| 123 | { |
| 124 | return m_opaque_sp->GetArguments().GetArgumentCount(); |
| 125 | } |
| 126 | |
| 127 | const char * |
| 128 | SBLaunchInfo::GetArgumentAtIndex (uint32_t idx) |
| 129 | { |
| 130 | return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx); |
| 131 | } |
| 132 | |
| 133 | void |
| 134 | SBLaunchInfo::SetArguments (const char **argv, bool append) |
| 135 | { |
| 136 | if (append) |
| 137 | { |
| 138 | if (argv) |
| 139 | m_opaque_sp->GetArguments().AppendArguments(argv); |
| 140 | } |
| 141 | else |
| 142 | { |
| 143 | if (argv) |
| 144 | m_opaque_sp->GetArguments().SetArguments(argv); |
| 145 | else |
| 146 | m_opaque_sp->GetArguments().Clear(); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | uint32_t |
| 151 | SBLaunchInfo::GetNumEnvironmentEntries () |
| 152 | { |
| 153 | return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount(); |
| 154 | } |
| 155 | |
| 156 | const char * |
| 157 | SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx) |
| 158 | { |
| 159 | return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx); |
| 160 | } |
| 161 | |
| 162 | void |
| 163 | SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append) |
| 164 | { |
| 165 | if (append) |
| 166 | { |
| 167 | if (envp) |
| 168 | m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp); |
| 169 | } |
| 170 | else |
| 171 | { |
| 172 | if (envp) |
| 173 | m_opaque_sp->GetEnvironmentEntries().SetArguments(envp); |
| 174 | else |
| 175 | m_opaque_sp->GetEnvironmentEntries().Clear(); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | void |
| 180 | SBLaunchInfo::Clear () |
| 181 | { |
| 182 | m_opaque_sp->Clear(); |
| 183 | } |
| 184 | |
| 185 | const char * |
| 186 | SBLaunchInfo::GetWorkingDirectory () const |
| 187 | { |
| 188 | return m_opaque_sp->GetWorkingDirectory(); |
| 189 | } |
| 190 | |
| 191 | void |
| 192 | SBLaunchInfo::SetWorkingDirectory (const char *working_dir) |
| 193 | { |
| 194 | m_opaque_sp->SetWorkingDirectory(working_dir); |
| 195 | } |
| 196 | |
| 197 | uint32_t |
| 198 | SBLaunchInfo::GetLaunchFlags () |
| 199 | { |
| 200 | return m_opaque_sp->GetFlags().Get(); |
| 201 | } |
| 202 | |
| 203 | void |
| 204 | SBLaunchInfo::SetLaunchFlags (uint32_t flags) |
| 205 | { |
| 206 | m_opaque_sp->GetFlags().Reset(flags); |
| 207 | } |
| 208 | |
| 209 | const char * |
| 210 | SBLaunchInfo::GetProcessPluginName () |
| 211 | { |
| 212 | return m_opaque_sp->GetProcessPluginName(); |
| 213 | } |
| 214 | |
| 215 | void |
| 216 | SBLaunchInfo::SetProcessPluginName (const char *plugin_name) |
| 217 | { |
| 218 | return m_opaque_sp->SetProcessPluginName (plugin_name); |
| 219 | } |
| 220 | |
| 221 | const char * |
| 222 | SBLaunchInfo::GetShell () |
| 223 | { |
| 224 | return m_opaque_sp->GetShell(); |
| 225 | } |
| 226 | |
| 227 | void |
| 228 | SBLaunchInfo::SetShell (const char * path) |
| 229 | { |
| 230 | m_opaque_sp->SetShell (path); |
| 231 | } |
| 232 | |
| 233 | uint32_t |
| 234 | SBLaunchInfo::GetResumeCount () |
| 235 | { |
| 236 | return m_opaque_sp->GetResumeCount(); |
| 237 | } |
| 238 | |
| 239 | void |
| 240 | SBLaunchInfo::SetResumeCount (uint32_t c) |
| 241 | { |
| 242 | m_opaque_sp->SetResumeCount (c); |
| 243 | } |
| 244 | |
| 245 | bool |
| 246 | SBLaunchInfo::AddCloseFileAction (int fd) |
| 247 | { |
| 248 | return m_opaque_sp->AppendCloseFileAction(fd); |
| 249 | } |
| 250 | |
| 251 | bool |
| 252 | SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd) |
| 253 | { |
| 254 | return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd); |
| 255 | } |
| 256 | |
| 257 | bool |
| 258 | SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write) |
| 259 | { |
| 260 | return m_opaque_sp->AppendOpenFileAction(fd, path, read, write); |
| 261 | } |
| 262 | |
| 263 | bool |
| 264 | SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write) |
| 265 | { |
| 266 | return m_opaque_sp->AppendSuppressFileAction(fd, read, write); |
| 267 | } |
| 268 | |
| 269 | |
| 270 | SBAttachInfo::SBAttachInfo () : |
Greg Clayton | ecc7c0d | 2012-03-07 23:52:51 +0000 | [diff] [blame] | 271 | m_opaque_sp (new ProcessAttachInfo()) |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 272 | { |
| 273 | } |
| 274 | |
| 275 | SBAttachInfo::SBAttachInfo (lldb::pid_t pid) : |
Greg Clayton | ecc7c0d | 2012-03-07 23:52:51 +0000 | [diff] [blame] | 276 | m_opaque_sp (new ProcessAttachInfo()) |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 277 | { |
| 278 | m_opaque_sp->SetProcessID (pid); |
| 279 | } |
| 280 | |
| 281 | SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) : |
Greg Clayton | ecc7c0d | 2012-03-07 23:52:51 +0000 | [diff] [blame] | 282 | m_opaque_sp (new ProcessAttachInfo()) |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 283 | { |
| 284 | if (path && path[0]) |
| 285 | m_opaque_sp->GetExecutableFile().SetFile(path, false); |
| 286 | m_opaque_sp->SetWaitForLaunch (wait_for); |
| 287 | } |
| 288 | |
| 289 | SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) : |
Greg Clayton | ecc7c0d | 2012-03-07 23:52:51 +0000 | [diff] [blame] | 290 | m_opaque_sp (new ProcessAttachInfo()) |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 291 | { |
| 292 | *m_opaque_sp = *rhs.m_opaque_sp; |
| 293 | } |
| 294 | |
Greg Clayton | ecc7c0d | 2012-03-07 23:52:51 +0000 | [diff] [blame] | 295 | SBAttachInfo::~SBAttachInfo() |
| 296 | { |
| 297 | } |
| 298 | |
| 299 | lldb_private::ProcessAttachInfo & |
| 300 | SBAttachInfo::ref () |
| 301 | { |
| 302 | return *m_opaque_sp; |
| 303 | } |
| 304 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 305 | SBAttachInfo & |
| 306 | SBAttachInfo::operator = (const SBAttachInfo &rhs) |
| 307 | { |
| 308 | if (this != &rhs) |
| 309 | *m_opaque_sp = *rhs.m_opaque_sp; |
| 310 | return *this; |
| 311 | } |
| 312 | |
| 313 | lldb::pid_t |
| 314 | SBAttachInfo::GetProcessID () |
| 315 | { |
| 316 | return m_opaque_sp->GetProcessID(); |
| 317 | } |
| 318 | |
| 319 | void |
| 320 | SBAttachInfo::SetProcessID (lldb::pid_t pid) |
| 321 | { |
| 322 | m_opaque_sp->SetProcessID (pid); |
| 323 | } |
| 324 | |
| 325 | |
| 326 | uint32_t |
| 327 | SBAttachInfo::GetResumeCount () |
| 328 | { |
| 329 | return m_opaque_sp->GetResumeCount(); |
| 330 | } |
| 331 | |
| 332 | void |
| 333 | SBAttachInfo::SetResumeCount (uint32_t c) |
| 334 | { |
| 335 | m_opaque_sp->SetResumeCount (c); |
| 336 | } |
| 337 | |
| 338 | const char * |
| 339 | SBAttachInfo::GetProcessPluginName () |
| 340 | { |
| 341 | return m_opaque_sp->GetProcessPluginName(); |
| 342 | } |
| 343 | |
| 344 | void |
| 345 | SBAttachInfo::SetProcessPluginName (const char *plugin_name) |
| 346 | { |
| 347 | return m_opaque_sp->SetProcessPluginName (plugin_name); |
| 348 | } |
| 349 | |
| 350 | void |
| 351 | SBAttachInfo::SetExecutable (const char *path) |
| 352 | { |
| 353 | if (path && path[0]) |
| 354 | m_opaque_sp->GetExecutableFile().SetFile(path, false); |
| 355 | else |
| 356 | m_opaque_sp->GetExecutableFile().Clear(); |
| 357 | } |
| 358 | |
| 359 | void |
| 360 | SBAttachInfo::SetExecutable (SBFileSpec exe_file) |
| 361 | { |
| 362 | if (exe_file.IsValid()) |
| 363 | m_opaque_sp->GetExecutableFile() = exe_file.ref(); |
| 364 | else |
| 365 | m_opaque_sp->GetExecutableFile().Clear(); |
| 366 | } |
| 367 | |
| 368 | bool |
| 369 | SBAttachInfo::GetWaitForLaunch () |
| 370 | { |
| 371 | return m_opaque_sp->GetWaitForLaunch(); |
| 372 | } |
| 373 | |
| 374 | void |
| 375 | SBAttachInfo::SetWaitForLaunch (bool b) |
| 376 | { |
| 377 | m_opaque_sp->SetWaitForLaunch (b); |
| 378 | } |
| 379 | |
Jim Ingham | cd16df9 | 2012-07-20 21:37:13 +0000 | [diff] [blame] | 380 | bool |
| 381 | SBAttachInfo::GetIgnoreExisting () |
| 382 | { |
| 383 | return m_opaque_sp->GetIgnoreExisting(); |
| 384 | } |
| 385 | |
| 386 | void |
| 387 | SBAttachInfo::SetIgnoreExisting (bool b) |
| 388 | { |
| 389 | m_opaque_sp->SetIgnoreExisting (b); |
| 390 | } |
| 391 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 392 | uint32_t |
Greg Clayton | 41bd8ac | 2012-02-24 23:56:06 +0000 | [diff] [blame] | 393 | SBAttachInfo::GetUserID() |
| 394 | { |
| 395 | return m_opaque_sp->GetUserID(); |
| 396 | } |
| 397 | |
| 398 | uint32_t |
| 399 | SBAttachInfo::GetGroupID() |
| 400 | { |
| 401 | return m_opaque_sp->GetGroupID(); |
| 402 | } |
| 403 | |
| 404 | bool |
| 405 | SBAttachInfo::UserIDIsValid () |
| 406 | { |
| 407 | return m_opaque_sp->UserIDIsValid(); |
| 408 | } |
| 409 | |
| 410 | bool |
| 411 | SBAttachInfo::GroupIDIsValid () |
| 412 | { |
| 413 | return m_opaque_sp->GroupIDIsValid(); |
| 414 | } |
| 415 | |
| 416 | void |
| 417 | SBAttachInfo::SetUserID (uint32_t uid) |
| 418 | { |
| 419 | m_opaque_sp->SetUserID (uid); |
| 420 | } |
| 421 | |
| 422 | void |
| 423 | SBAttachInfo::SetGroupID (uint32_t gid) |
| 424 | { |
| 425 | m_opaque_sp->SetGroupID (gid); |
| 426 | } |
| 427 | |
| 428 | uint32_t |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 429 | SBAttachInfo::GetEffectiveUserID() |
| 430 | { |
| 431 | return m_opaque_sp->GetEffectiveUserID(); |
| 432 | } |
| 433 | |
| 434 | uint32_t |
| 435 | SBAttachInfo::GetEffectiveGroupID() |
| 436 | { |
| 437 | return m_opaque_sp->GetEffectiveGroupID(); |
| 438 | } |
| 439 | |
| 440 | bool |
| 441 | SBAttachInfo::EffectiveUserIDIsValid () |
| 442 | { |
| 443 | return m_opaque_sp->EffectiveUserIDIsValid(); |
| 444 | } |
| 445 | |
| 446 | bool |
| 447 | SBAttachInfo::EffectiveGroupIDIsValid () |
| 448 | { |
| 449 | return m_opaque_sp->EffectiveGroupIDIsValid (); |
| 450 | } |
| 451 | |
| 452 | void |
| 453 | SBAttachInfo::SetEffectiveUserID (uint32_t uid) |
| 454 | { |
| 455 | m_opaque_sp->SetEffectiveUserID(uid); |
| 456 | } |
| 457 | |
| 458 | void |
| 459 | SBAttachInfo::SetEffectiveGroupID (uint32_t gid) |
| 460 | { |
| 461 | m_opaque_sp->SetEffectiveGroupID(gid); |
| 462 | } |
| 463 | |
| 464 | lldb::pid_t |
| 465 | SBAttachInfo::GetParentProcessID () |
| 466 | { |
| 467 | return m_opaque_sp->GetParentProcessID(); |
| 468 | } |
| 469 | |
| 470 | void |
| 471 | SBAttachInfo::SetParentProcessID (lldb::pid_t pid) |
| 472 | { |
| 473 | m_opaque_sp->SetParentProcessID (pid); |
| 474 | } |
| 475 | |
| 476 | bool |
| 477 | SBAttachInfo::ParentProcessIDIsValid() |
| 478 | { |
| 479 | return m_opaque_sp->ParentProcessIDIsValid(); |
| 480 | } |
| 481 | |
| 482 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 483 | //---------------------------------------------------------------------- |
| 484 | // SBTarget constructor |
| 485 | //---------------------------------------------------------------------- |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 486 | SBTarget::SBTarget () : |
| 487 | m_opaque_sp () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 488 | { |
| 489 | } |
| 490 | |
| 491 | SBTarget::SBTarget (const SBTarget& rhs) : |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 492 | m_opaque_sp (rhs.m_opaque_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 493 | { |
| 494 | } |
| 495 | |
| 496 | SBTarget::SBTarget(const TargetSP& target_sp) : |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 497 | m_opaque_sp (target_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 498 | { |
| 499 | } |
| 500 | |
Greg Clayton | efabb12 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 501 | const SBTarget& |
| 502 | SBTarget::operator = (const SBTarget& rhs) |
| 503 | { |
| 504 | if (this != &rhs) |
| 505 | m_opaque_sp = rhs.m_opaque_sp; |
| 506 | return *this; |
| 507 | } |
| 508 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 509 | //---------------------------------------------------------------------- |
| 510 | // Destructor |
| 511 | //---------------------------------------------------------------------- |
| 512 | SBTarget::~SBTarget() |
| 513 | { |
| 514 | } |
| 515 | |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 516 | const char * |
| 517 | SBTarget::GetBroadcasterClassName () |
| 518 | { |
| 519 | return Target::GetStaticBroadcasterClass().AsCString(); |
| 520 | } |
| 521 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 522 | bool |
| 523 | SBTarget::IsValid () const |
| 524 | { |
Filipe Cabecinhas | 721ba3f | 2012-05-19 09:59:08 +0000 | [diff] [blame] | 525 | return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | SBProcess |
| 529 | SBTarget::GetProcess () |
| 530 | { |
| 531 | SBProcess sb_process; |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 532 | ProcessSP process_sp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 533 | TargetSP target_sp(GetSP()); |
| 534 | if (target_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 535 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 536 | process_sp = target_sp->GetProcessSP(); |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 537 | sb_process.SetSP (process_sp); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 538 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 539 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 540 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 541 | if (log) |
| 542 | { |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 543 | log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 544 | target_sp.get(), process_sp.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 547 | return sb_process; |
| 548 | } |
| 549 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 550 | SBDebugger |
| 551 | SBTarget::GetDebugger () const |
| 552 | { |
| 553 | SBDebugger debugger; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 554 | TargetSP target_sp(GetSP()); |
| 555 | if (target_sp) |
| 556 | debugger.reset (target_sp->GetDebugger().shared_from_this()); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 557 | return debugger; |
| 558 | } |
| 559 | |
Jim Ingham | 270684d | 2011-03-31 00:01:24 +0000 | [diff] [blame] | 560 | SBProcess |
Greg Clayton | 4d8ad55 | 2013-03-25 22:40:51 +0000 | [diff] [blame] | 561 | SBTarget::LoadCore (const char *core_file) |
| 562 | { |
| 563 | SBProcess sb_process; |
| 564 | TargetSP target_sp(GetSP()); |
| 565 | if (target_sp) |
| 566 | { |
| 567 | FileSpec filespec(core_file, true); |
| 568 | ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(), |
| 569 | NULL, |
| 570 | &filespec)); |
| 571 | if (process_sp) |
| 572 | { |
| 573 | process_sp->LoadCore(); |
| 574 | sb_process.SetSP (process_sp); |
| 575 | } |
| 576 | } |
| 577 | return sb_process; |
| 578 | } |
| 579 | |
| 580 | SBProcess |
Jim Ingham | 270684d | 2011-03-31 00:01:24 +0000 | [diff] [blame] | 581 | SBTarget::LaunchSimple |
| 582 | ( |
| 583 | char const **argv, |
| 584 | char const **envp, |
| 585 | const char *working_directory |
| 586 | ) |
| 587 | { |
| 588 | char *stdin_path = NULL; |
| 589 | char *stdout_path = NULL; |
| 590 | char *stderr_path = NULL; |
| 591 | uint32_t launch_flags = 0; |
| 592 | bool stop_at_entry = false; |
| 593 | SBError error; |
| 594 | SBListener listener = GetDebugger().GetListener(); |
| 595 | return Launch (listener, |
| 596 | argv, |
| 597 | envp, |
| 598 | stdin_path, |
| 599 | stdout_path, |
| 600 | stderr_path, |
| 601 | working_directory, |
| 602 | launch_flags, |
| 603 | stop_at_entry, |
| 604 | error); |
| 605 | } |
Greg Clayton | bd82a5d | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 606 | |
| 607 | SBProcess |
| 608 | SBTarget::Launch |
| 609 | ( |
Greg Clayton | 4b04562 | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 610 | SBListener &listener, |
Greg Clayton | bd82a5d | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 611 | char const **argv, |
| 612 | char const **envp, |
| 613 | const char *stdin_path, |
| 614 | const char *stdout_path, |
| 615 | const char *stderr_path, |
| 616 | const char *working_directory, |
| 617 | uint32_t launch_flags, // See LaunchFlags |
| 618 | bool stop_at_entry, |
| 619 | lldb::SBError& error |
| 620 | ) |
| 621 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 622 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 623 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 624 | SBProcess sb_process; |
| 625 | ProcessSP process_sp; |
| 626 | TargetSP target_sp(GetSP()); |
| 627 | |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 628 | if (log) |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 629 | { |
Greg Clayton | bd82a5d | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 630 | log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 631 | target_sp.get(), |
Greg Clayton | bd82a5d | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 632 | argv, |
| 633 | envp, |
| 634 | stdin_path ? stdin_path : "NULL", |
| 635 | stdout_path ? stdout_path : "NULL", |
| 636 | stderr_path ? stderr_path : "NULL", |
| 637 | working_directory ? working_directory : "NULL", |
| 638 | launch_flags, |
| 639 | stop_at_entry, |
| 640 | error.get()); |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 641 | } |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 642 | |
| 643 | if (target_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 644 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 645 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Greg Clayton | 5d5028b | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 646 | |
Greg Clayton | 645bf54 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 647 | if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR")) |
| 648 | launch_flags |= eLaunchFlagDisableASLR; |
| 649 | |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 650 | StateType state = eStateInvalid; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 651 | process_sp = target_sp->GetProcessSP(); |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 652 | if (process_sp) |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 653 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 654 | state = process_sp->GetState(); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 655 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 656 | if (process_sp->IsAlive() && state != eStateConnected) |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 657 | { |
| 658 | if (state == eStateAttaching) |
| 659 | error.SetErrorString ("process attach is in progress"); |
| 660 | else |
| 661 | error.SetErrorString ("a process is already being debugged"); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 662 | return sb_process; |
| 663 | } |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 664 | } |
| 665 | |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 666 | if (state == eStateConnected) |
| 667 | { |
| 668 | // If we are already connected, then we have already specified the |
| 669 | // listener, so if a valid listener is supplied, we need to error out |
| 670 | // to let the client know. |
| 671 | if (listener.IsValid()) |
| 672 | { |
| 673 | error.SetErrorString ("process is connected and already has a listener, pass empty listener"); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 674 | return sb_process; |
| 675 | } |
| 676 | } |
| 677 | else |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 678 | { |
Greg Clayton | 4b04562 | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 679 | if (listener.IsValid()) |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 680 | process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL); |
Greg Clayton | 4b04562 | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 681 | else |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 682 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 683 | } |
Greg Clayton | 645bf54 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 684 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 685 | if (process_sp) |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 686 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 687 | sb_process.SetSP (process_sp); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 688 | if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO")) |
| 689 | launch_flags |= eLaunchFlagDisableSTDIO; |
| 690 | |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 691 | ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags); |
| 692 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 693 | Module *exe_module = target_sp->GetExecutableModulePointer(); |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 694 | if (exe_module) |
Greg Clayton | ad9e828 | 2011-11-29 04:03:30 +0000 | [diff] [blame] | 695 | launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 696 | if (argv) |
| 697 | launch_info.GetArguments().AppendArguments (argv); |
| 698 | if (envp) |
| 699 | launch_info.GetEnvironmentEntries ().SetArguments (envp); |
| 700 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 701 | error.SetError (process_sp->Launch (launch_info)); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 702 | if (error.Success()) |
Greg Clayton | 645bf54 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 703 | { |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 704 | // We we are stopping at the entry point, we can return now! |
| 705 | if (stop_at_entry) |
| 706 | return sb_process; |
Greg Clayton | 645bf54 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 707 | |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 708 | // Make sure we are stopped at the entry |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 709 | StateType state = process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 710 | if (state == eStateStopped) |
Greg Clayton | 645bf54 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 711 | { |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 712 | // resume the process to skip the entry point |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 713 | error.SetError (process_sp->Resume()); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 714 | if (error.Success()) |
Greg Clayton | 645bf54 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 715 | { |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 716 | // If we are doing synchronous mode, then wait for the |
| 717 | // process to stop yet again! |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 718 | if (target_sp->GetDebugger().GetAsyncExecution () == false) |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 719 | process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | 645bf54 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | } |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 723 | } |
| 724 | else |
| 725 | { |
| 726 | error.SetErrorString ("unable to create lldb_private::Process"); |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | else |
| 730 | { |
| 731 | error.SetErrorString ("SBTarget is invalid"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 732 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 733 | |
Caroline Tice | 20ad3c4 | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 734 | log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 735 | if (log) |
| 736 | { |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 737 | log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 738 | target_sp.get(), process_sp.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 739 | } |
| 740 | |
Greg Clayton | 5d5028b | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 741 | return sb_process; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 744 | SBProcess |
| 745 | SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error) |
| 746 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 747 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 748 | |
| 749 | SBProcess sb_process; |
| 750 | ProcessSP process_sp; |
| 751 | TargetSP target_sp(GetSP()); |
| 752 | |
| 753 | if (log) |
| 754 | { |
| 755 | log->Printf ("SBTarget(%p)::Launch (launch_info, error)...", target_sp.get()); |
| 756 | } |
| 757 | |
| 758 | if (target_sp) |
| 759 | { |
| 760 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 761 | StateType state = eStateInvalid; |
| 762 | process_sp = target_sp->GetProcessSP(); |
| 763 | if (process_sp) |
| 764 | { |
| 765 | state = process_sp->GetState(); |
| 766 | |
| 767 | if (process_sp->IsAlive() && state != eStateConnected) |
| 768 | { |
| 769 | if (state == eStateAttaching) |
| 770 | error.SetErrorString ("process attach is in progress"); |
| 771 | else |
| 772 | error.SetErrorString ("a process is already being debugged"); |
| 773 | return sb_process; |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | if (state != eStateConnected) |
| 778 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); |
| 779 | |
| 780 | if (process_sp) |
| 781 | { |
| 782 | sb_process.SetSP (process_sp); |
| 783 | lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref(); |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 784 | |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 785 | Module *exe_module = target_sp->GetExecutableModulePointer(); |
| 786 | if (exe_module) |
Han Ming Ong | 04cf1ba | 2012-03-02 01:02:04 +0000 | [diff] [blame] | 787 | launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 788 | |
| 789 | const ArchSpec &arch_spec = target_sp->GetArchitecture(); |
| 790 | if (arch_spec.IsValid()) |
| 791 | launch_info.GetArchitecture () = arch_spec; |
| 792 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 793 | error.SetError (process_sp->Launch (launch_info)); |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 794 | const bool synchronous_execution = target_sp->GetDebugger().GetAsyncExecution () == false; |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 795 | if (error.Success()) |
| 796 | { |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 797 | if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry)) |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 798 | { |
| 799 | // If we are doing synchronous mode, then wait for the initial |
| 800 | // stop to happen, else, return and let the caller watch for |
| 801 | // the stop |
| 802 | if (synchronous_execution) |
Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 803 | process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 804 | // We we are stopping at the entry point, we can return now! |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 805 | return sb_process; |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 806 | } |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 807 | |
| 808 | // Make sure we are stopped at the entry |
Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 809 | StateType state = process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 810 | if (state == eStateStopped) |
| 811 | { |
| 812 | // resume the process to skip the entry point |
| 813 | error.SetError (process_sp->Resume()); |
| 814 | if (error.Success()) |
| 815 | { |
| 816 | // If we are doing synchronous mode, then wait for the |
| 817 | // process to stop yet again! |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 818 | if (synchronous_execution) |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 819 | process_sp->WaitForProcessToStop (NULL); |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | else |
| 825 | { |
| 826 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 827 | } |
| 828 | } |
| 829 | else |
| 830 | { |
| 831 | error.SetErrorString ("SBTarget is invalid"); |
| 832 | } |
| 833 | |
| 834 | log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 835 | if (log) |
| 836 | { |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 837 | log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)", |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 838 | target_sp.get(), process_sp.get()); |
| 839 | } |
| 840 | |
| 841 | return sb_process; |
| 842 | } |
| 843 | |
| 844 | lldb::SBProcess |
| 845 | SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error) |
| 846 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 847 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 848 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 849 | SBProcess sb_process; |
| 850 | ProcessSP process_sp; |
| 851 | TargetSP target_sp(GetSP()); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 852 | |
| 853 | if (log) |
| 854 | { |
| 855 | log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...", target_sp.get()); |
| 856 | } |
| 857 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 858 | if (target_sp) |
| 859 | { |
| 860 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 861 | |
| 862 | StateType state = eStateInvalid; |
| 863 | process_sp = target_sp->GetProcessSP(); |
| 864 | if (process_sp) |
| 865 | { |
| 866 | state = process_sp->GetState(); |
| 867 | |
| 868 | if (process_sp->IsAlive() && state != eStateConnected) |
| 869 | { |
| 870 | if (state == eStateAttaching) |
| 871 | error.SetErrorString ("process attach is in progress"); |
| 872 | else |
| 873 | error.SetErrorString ("a process is already being debugged"); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 874 | if (log) |
| 875 | { |
| 876 | log->Printf ("SBTarget(%p)::Attach (...) => error %s", |
| 877 | target_sp.get(), error.GetCString()); |
| 878 | } |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 879 | return sb_process; |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | if (state != eStateConnected) |
| 884 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); |
| 885 | |
| 886 | if (process_sp) |
| 887 | { |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 888 | ProcessAttachInfo &attach_info = sb_attach_info.ref(); |
Han Ming Ong | fbd8de8 | 2013-03-25 20:11:18 +0000 | [diff] [blame] | 889 | if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid()) |
Han Ming Ong | cec8c90 | 2012-02-29 00:12:56 +0000 | [diff] [blame] | 890 | { |
| 891 | PlatformSP platform_sp = target_sp->GetPlatform(); |
Greg Clayton | 91e407e | 2012-09-27 00:03:39 +0000 | [diff] [blame] | 892 | // See if we can pre-verify if a process exists or not |
| 893 | if (platform_sp && platform_sp->IsConnected()) |
Han Ming Ong | cec8c90 | 2012-02-29 00:12:56 +0000 | [diff] [blame] | 894 | { |
Han Ming Ong | fbd8de8 | 2013-03-25 20:11:18 +0000 | [diff] [blame] | 895 | lldb::pid_t attach_pid = attach_info.GetProcessID(); |
Greg Clayton | 91e407e | 2012-09-27 00:03:39 +0000 | [diff] [blame] | 896 | ProcessInstanceInfo instance_info; |
| 897 | if (platform_sp->GetProcessInfo(attach_pid, instance_info)) |
| 898 | { |
| 899 | attach_info.SetUserID(instance_info.GetEffectiveUserID()); |
| 900 | } |
| 901 | else |
| 902 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 903 | error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 904 | if (log) |
| 905 | { |
| 906 | log->Printf ("SBTarget(%p)::Attach (...) => error %s", |
| 907 | target_sp.get(), error.GetCString()); |
| 908 | } |
Greg Clayton | 91e407e | 2012-09-27 00:03:39 +0000 | [diff] [blame] | 909 | return sb_process; |
| 910 | } |
Han Ming Ong | cec8c90 | 2012-02-29 00:12:56 +0000 | [diff] [blame] | 911 | } |
| 912 | } |
Han Ming Ong | bee9839 | 2012-02-29 19:16:40 +0000 | [diff] [blame] | 913 | error.SetError (process_sp->Attach (attach_info)); |
| 914 | if (error.Success()) |
| 915 | { |
| 916 | sb_process.SetSP (process_sp); |
| 917 | // If we are doing synchronous mode, then wait for the |
| 918 | // process to stop! |
| 919 | if (target_sp->GetDebugger().GetAsyncExecution () == false) |
| 920 | process_sp->WaitForProcessToStop (NULL); |
| 921 | } |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 922 | } |
| 923 | else |
| 924 | { |
| 925 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 926 | } |
| 927 | } |
| 928 | else |
| 929 | { |
| 930 | error.SetErrorString ("SBTarget is invalid"); |
| 931 | } |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 932 | |
| 933 | if (log) |
| 934 | { |
| 935 | log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)", |
| 936 | target_sp.get(), process_sp.get()); |
| 937 | } |
| 938 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 939 | return sb_process; |
| 940 | } |
| 941 | |
| 942 | |
Greg Clayton | 1ba6cfd | 2011-12-02 02:10:57 +0000 | [diff] [blame] | 943 | #if defined(__APPLE__) |
| 944 | |
| 945 | lldb::SBProcess |
| 946 | SBTarget::AttachToProcessWithID (SBListener &listener, |
| 947 | ::pid_t pid, |
| 948 | lldb::SBError& error) |
| 949 | { |
| 950 | return AttachToProcessWithID (listener, (lldb::pid_t)pid, error); |
| 951 | } |
| 952 | |
| 953 | #endif // #if defined(__APPLE__) |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 954 | |
| 955 | lldb::SBProcess |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 956 | SBTarget::AttachToProcessWithID |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 957 | ( |
Greg Clayton | 4b04562 | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 958 | SBListener &listener, |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 959 | lldb::pid_t pid,// The process ID to attach to |
| 960 | SBError& error // An error explaining what went wrong if attach fails |
| 961 | ) |
| 962 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 963 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 964 | |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 965 | SBProcess sb_process; |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 966 | ProcessSP process_sp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 967 | TargetSP target_sp(GetSP()); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 968 | |
| 969 | if (log) |
| 970 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 971 | log->Printf ("SBTarget(%p)::AttachToProcessWithID (listener, pid=%" PRId64 ", error)...", target_sp.get(), pid); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 974 | if (target_sp) |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 975 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 976 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 977 | |
| 978 | StateType state = eStateInvalid; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 979 | process_sp = target_sp->GetProcessSP(); |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 980 | if (process_sp) |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 981 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 982 | state = process_sp->GetState(); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 983 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 984 | if (process_sp->IsAlive() && state != eStateConnected) |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 985 | { |
| 986 | if (state == eStateAttaching) |
| 987 | error.SetErrorString ("process attach is in progress"); |
| 988 | else |
| 989 | error.SetErrorString ("a process is already being debugged"); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 990 | return sb_process; |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | if (state == eStateConnected) |
| 995 | { |
| 996 | // If we are already connected, then we have already specified the |
| 997 | // listener, so if a valid listener is supplied, we need to error out |
| 998 | // to let the client know. |
| 999 | if (listener.IsValid()) |
| 1000 | { |
| 1001 | error.SetErrorString ("process is connected and already has a listener, pass empty listener"); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1002 | return sb_process; |
| 1003 | } |
| 1004 | } |
Greg Clayton | 4b04562 | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 1005 | else |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1006 | { |
| 1007 | if (listener.IsValid()) |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 1008 | process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1009 | else |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 1010 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1011 | } |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1012 | if (process_sp) |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1013 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1014 | sb_process.SetSP (process_sp); |
| 1015 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 1016 | ProcessAttachInfo attach_info; |
| 1017 | attach_info.SetProcessID (pid); |
Han Ming Ong | 8464704 | 2012-02-25 01:07:38 +0000 | [diff] [blame] | 1018 | |
| 1019 | PlatformSP platform_sp = target_sp->GetPlatform(); |
| 1020 | ProcessInstanceInfo instance_info; |
| 1021 | if (platform_sp->GetProcessInfo(pid, instance_info)) |
| 1022 | { |
| 1023 | attach_info.SetUserID(instance_info.GetEffectiveUserID()); |
Han Ming Ong | 8464704 | 2012-02-25 01:07:38 +0000 | [diff] [blame] | 1024 | } |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1025 | error.SetError (process_sp->Attach (attach_info)); |
Greg Clayton | e2186ed | 2012-09-07 17:51:47 +0000 | [diff] [blame] | 1026 | if (error.Success()) |
| 1027 | { |
| 1028 | // If we are doing synchronous mode, then wait for the |
| 1029 | // process to stop! |
| 1030 | if (target_sp->GetDebugger().GetAsyncExecution () == false) |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1031 | process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | e2186ed | 2012-09-07 17:51:47 +0000 | [diff] [blame] | 1032 | } |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1033 | } |
| 1034 | else |
| 1035 | { |
| 1036 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 1037 | } |
| 1038 | } |
| 1039 | else |
| 1040 | { |
| 1041 | error.SetErrorString ("SBTarget is invalid"); |
| 1042 | } |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 1043 | |
| 1044 | if (log) |
| 1045 | { |
| 1046 | log->Printf ("SBTarget(%p)::AttachToProcessWithID (...) => SBProcess(%p)", |
| 1047 | target_sp.get(), process_sp.get()); |
| 1048 | } |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1049 | return sb_process; |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | lldb::SBProcess |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 1053 | SBTarget::AttachToProcessWithName |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1054 | ( |
Greg Clayton | 4b04562 | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 1055 | SBListener &listener, |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1056 | const char *name, // basename of process to attach to |
| 1057 | bool wait_for, // if true wait for a new instance of "name" to be launched |
| 1058 | SBError& error // An error explaining what went wrong if attach fails |
| 1059 | ) |
| 1060 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1061 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 1062 | |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1063 | SBProcess sb_process; |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1064 | ProcessSP process_sp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1065 | TargetSP target_sp(GetSP()); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 1066 | |
| 1067 | if (log) |
| 1068 | { |
| 1069 | log->Printf ("SBTarget(%p)::AttachToProcessWithName (listener, name=%s, wait_for=%s, error)...", target_sp.get(), name, wait_for ? "true" : "false"); |
| 1070 | } |
| 1071 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1072 | if (name && target_sp) |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1073 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1074 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1075 | |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1076 | StateType state = eStateInvalid; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1077 | process_sp = target_sp->GetProcessSP(); |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1078 | if (process_sp) |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1079 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1080 | state = process_sp->GetState(); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1081 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1082 | if (process_sp->IsAlive() && state != eStateConnected) |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1083 | { |
| 1084 | if (state == eStateAttaching) |
| 1085 | error.SetErrorString ("process attach is in progress"); |
| 1086 | else |
| 1087 | error.SetErrorString ("a process is already being debugged"); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1088 | return sb_process; |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | if (state == eStateConnected) |
| 1093 | { |
| 1094 | // If we are already connected, then we have already specified the |
| 1095 | // listener, so if a valid listener is supplied, we need to error out |
| 1096 | // to let the client know. |
| 1097 | if (listener.IsValid()) |
| 1098 | { |
| 1099 | error.SetErrorString ("process is connected and already has a listener, pass empty listener"); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1100 | return sb_process; |
| 1101 | } |
| 1102 | } |
Greg Clayton | 4b04562 | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 1103 | else |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1104 | { |
| 1105 | if (listener.IsValid()) |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 1106 | process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1107 | else |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 1108 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1109 | } |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1110 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1111 | if (process_sp) |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1112 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1113 | sb_process.SetSP (process_sp); |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 1114 | ProcessAttachInfo attach_info; |
| 1115 | attach_info.GetExecutableFile().SetFile(name, false); |
| 1116 | attach_info.SetWaitForLaunch(wait_for); |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1117 | error.SetError (process_sp->Attach (attach_info)); |
Daniel Malea | d659dc1 | 2013-04-01 19:47:00 +0000 | [diff] [blame] | 1118 | if (error.Success()) |
| 1119 | { |
| 1120 | // If we are doing synchronous mode, then wait for the |
| 1121 | // process to stop! |
| 1122 | if (target_sp->GetDebugger().GetAsyncExecution () == false) |
| 1123 | process_sp->WaitForProcessToStop (NULL); |
| 1124 | } |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1125 | } |
| 1126 | else |
| 1127 | { |
| 1128 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 1129 | } |
| 1130 | } |
| 1131 | else |
| 1132 | { |
| 1133 | error.SetErrorString ("SBTarget is invalid"); |
| 1134 | } |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 1135 | |
| 1136 | if (log) |
| 1137 | { |
| 1138 | log->Printf ("SBTarget(%p)::AttachToPorcessWithName (...) => SBProcess(%p)", |
| 1139 | target_sp.get(), process_sp.get()); |
| 1140 | } |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1141 | return sb_process; |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1144 | lldb::SBProcess |
| 1145 | SBTarget::ConnectRemote |
| 1146 | ( |
| 1147 | SBListener &listener, |
| 1148 | const char *url, |
| 1149 | const char *plugin_name, |
| 1150 | SBError& error |
| 1151 | ) |
| 1152 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1153 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 1154 | |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1155 | SBProcess sb_process; |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1156 | ProcessSP process_sp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1157 | TargetSP target_sp(GetSP()); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 1158 | |
| 1159 | if (log) |
| 1160 | { |
| 1161 | log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...", target_sp.get(), url, plugin_name); |
| 1162 | } |
| 1163 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1164 | if (target_sp) |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1165 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1166 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1167 | if (listener.IsValid()) |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 1168 | process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL); |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1169 | else |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 1170 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL); |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1171 | |
| 1172 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1173 | if (process_sp) |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1174 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1175 | sb_process.SetSP (process_sp); |
Jason Molenda | 4bd4e7e | 2012-09-29 04:02:01 +0000 | [diff] [blame] | 1176 | error.SetError (process_sp->ConnectRemote (NULL, url)); |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1177 | } |
| 1178 | else |
| 1179 | { |
| 1180 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 1181 | } |
| 1182 | } |
| 1183 | else |
| 1184 | { |
| 1185 | error.SetErrorString ("SBTarget is invalid"); |
| 1186 | } |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 1187 | |
| 1188 | if (log) |
| 1189 | { |
| 1190 | log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)", |
| 1191 | target_sp.get(), process_sp.get()); |
| 1192 | } |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1193 | return sb_process; |
| 1194 | } |
| 1195 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1196 | SBFileSpec |
| 1197 | SBTarget::GetExecutable () |
| 1198 | { |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1199 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1200 | SBFileSpec exe_file_spec; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1201 | TargetSP target_sp(GetSP()); |
| 1202 | if (target_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1203 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1204 | Module *exe_module = target_sp->GetExecutableModulePointer(); |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 1205 | if (exe_module) |
| 1206 | exe_file_spec.SetFileSpec (exe_module->GetFileSpec()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1207 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1208 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1209 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1210 | if (log) |
| 1211 | { |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1212 | log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1213 | target_sp.get(), exe_file_spec.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1216 | return exe_file_spec; |
| 1217 | } |
| 1218 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1219 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1220 | SBTarget::operator == (const SBTarget &rhs) const |
| 1221 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1222 | return m_opaque_sp.get() == rhs.m_opaque_sp.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | bool |
| 1226 | SBTarget::operator != (const SBTarget &rhs) const |
| 1227 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1228 | return m_opaque_sp.get() != rhs.m_opaque_sp.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1231 | lldb::TargetSP |
| 1232 | SBTarget::GetSP () const |
Greg Clayton | 9a37766 | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 1233 | { |
| 1234 | return m_opaque_sp; |
| 1235 | } |
| 1236 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1237 | void |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1238 | SBTarget::SetSP (const lldb::TargetSP& target_sp) |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1239 | { |
| 1240 | m_opaque_sp = target_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
Greg Clayton | 00e6fbf | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 1243 | lldb::SBAddress |
| 1244 | SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr) |
Greg Clayton | ac2eb9b | 2010-12-12 19:25:26 +0000 | [diff] [blame] | 1245 | { |
Greg Clayton | 00e6fbf | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 1246 | lldb::SBAddress sb_addr; |
| 1247 | Address &addr = sb_addr.ref(); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1248 | TargetSP target_sp(GetSP()); |
| 1249 | if (target_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1250 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1251 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1252 | if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr)) |
Greg Clayton | 00e6fbf | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 1253 | return sb_addr; |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1254 | } |
Greg Clayton | ac2eb9b | 2010-12-12 19:25:26 +0000 | [diff] [blame] | 1255 | |
Greg Clayton | 00e6fbf | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 1256 | // We have a load address that isn't in a section, just return an address |
| 1257 | // with the offset filled in (the address) and the section set to NULL |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1258 | addr.SetRawAddress(vm_addr); |
Greg Clayton | 00e6fbf | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 1259 | return sb_addr; |
Greg Clayton | ac2eb9b | 2010-12-12 19:25:26 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
Greg Clayton | 5f2a4f9 | 2011-03-02 21:34:46 +0000 | [diff] [blame] | 1262 | SBSymbolContext |
| 1263 | SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) |
| 1264 | { |
| 1265 | SBSymbolContext sc; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1266 | if (addr.IsValid()) |
| 1267 | { |
| 1268 | TargetSP target_sp(GetSP()); |
| 1269 | if (target_sp) |
| 1270 | target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref()); |
| 1271 | } |
Greg Clayton | 5f2a4f9 | 2011-03-02 21:34:46 +0000 | [diff] [blame] | 1272 | return sc; |
| 1273 | } |
| 1274 | |
| 1275 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1276 | SBBreakpoint |
| 1277 | SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line) |
| 1278 | { |
Greg Clayton | 7481c20 | 2010-11-08 00:28:40 +0000 | [diff] [blame] | 1279 | return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | SBBreakpoint |
| 1283 | SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line) |
| 1284 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1285 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1286 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1287 | SBBreakpoint sb_bp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1288 | TargetSP target_sp(GetSP()); |
| 1289 | if (target_sp && line != 0) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1290 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1291 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1292 | |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1293 | const LazyBool check_inlines = eLazyBoolCalculate; |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1294 | const LazyBool skip_prologue = eLazyBoolCalculate; |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1295 | const bool internal = false; |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1296 | *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1297 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1298 | |
| 1299 | if (log) |
| 1300 | { |
| 1301 | SBStream sstr; |
| 1302 | sb_bp.GetDescription (sstr); |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1303 | char path[PATH_MAX]; |
| 1304 | sb_file_spec->GetPath (path, sizeof(path)); |
| 1305 | log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1306 | target_sp.get(), |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1307 | path, |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1308 | line, |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1309 | sb_bp.get(), |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1310 | sstr.GetData()); |
| 1311 | } |
| 1312 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1313 | return sb_bp; |
| 1314 | } |
| 1315 | |
| 1316 | SBBreakpoint |
| 1317 | SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name) |
| 1318 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1319 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1320 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1321 | SBBreakpoint sb_bp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1322 | TargetSP target_sp(GetSP()); |
| 1323 | if (target_sp.get()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1324 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1325 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1326 | |
| 1327 | const bool internal = false; |
| 1328 | const LazyBool skip_prologue = eLazyBoolCalculate; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1329 | if (module_name && module_name[0]) |
| 1330 | { |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1331 | FileSpecList module_spec_list; |
| 1332 | module_spec_list.Append (FileSpec (module_name, false)); |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1333 | *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1334 | } |
| 1335 | else |
| 1336 | { |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1337 | *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1338 | } |
| 1339 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1340 | |
| 1341 | if (log) |
| 1342 | { |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1343 | log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1344 | target_sp.get(), symbol_name, module_name, sb_bp.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1347 | return sb_bp; |
| 1348 | } |
| 1349 | |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1350 | lldb::SBBreakpoint |
| 1351 | SBTarget::BreakpointCreateByName (const char *symbol_name, |
| 1352 | const SBFileSpecList &module_list, |
| 1353 | const SBFileSpecList &comp_unit_list) |
| 1354 | { |
Jim Ingham | 2dd7f7f | 2011-10-11 01:18:55 +0000 | [diff] [blame] | 1355 | uint32_t name_type_mask = eFunctionNameTypeAuto; |
| 1356 | return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list); |
| 1357 | } |
| 1358 | |
| 1359 | lldb::SBBreakpoint |
| 1360 | SBTarget::BreakpointCreateByName (const char *symbol_name, |
| 1361 | uint32_t name_type_mask, |
| 1362 | const SBFileSpecList &module_list, |
| 1363 | const SBFileSpecList &comp_unit_list) |
| 1364 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1365 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1366 | |
| 1367 | SBBreakpoint sb_bp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1368 | TargetSP target_sp(GetSP()); |
| 1369 | if (target_sp && symbol_name && symbol_name[0]) |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1370 | { |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1371 | const bool internal = false; |
| 1372 | const LazyBool skip_prologue = eLazyBoolCalculate; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1373 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1374 | *sb_bp = target_sp->CreateBreakpoint (module_list.get(), |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1375 | comp_unit_list.get(), |
| 1376 | symbol_name, |
Jim Ingham | 2dd7f7f | 2011-10-11 01:18:55 +0000 | [diff] [blame] | 1377 | name_type_mask, |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1378 | skip_prologue, |
| 1379 | internal); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | if (log) |
| 1383 | { |
Jim Ingham | 2dd7f7f | 2011-10-11 01:18:55 +0000 | [diff] [blame] | 1384 | log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1385 | target_sp.get(), symbol_name, name_type_mask, sb_bp.get()); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | return sb_bp; |
| 1389 | } |
| 1390 | |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1391 | lldb::SBBreakpoint |
| 1392 | SBTarget::BreakpointCreateByNames (const char *symbol_names[], |
| 1393 | uint32_t num_names, |
| 1394 | uint32_t name_type_mask, |
| 1395 | const SBFileSpecList &module_list, |
| 1396 | const SBFileSpecList &comp_unit_list) |
| 1397 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1398 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1399 | |
| 1400 | SBBreakpoint sb_bp; |
| 1401 | TargetSP target_sp(GetSP()); |
| 1402 | if (target_sp && num_names > 0) |
| 1403 | { |
| 1404 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1405 | const bool internal = false; |
| 1406 | const LazyBool skip_prologue = eLazyBoolCalculate; |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1407 | *sb_bp = target_sp->CreateBreakpoint (module_list.get(), |
| 1408 | comp_unit_list.get(), |
| 1409 | symbol_names, |
| 1410 | num_names, |
| 1411 | name_type_mask, |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1412 | skip_prologue, |
| 1413 | internal); |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | if (log) |
| 1417 | { |
| 1418 | log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={", target_sp.get()); |
| 1419 | for (uint32_t i = 0 ; i < num_names; i++) |
| 1420 | { |
| 1421 | char sep; |
| 1422 | if (i < num_names - 1) |
| 1423 | sep = ','; |
| 1424 | else |
| 1425 | sep = '}'; |
| 1426 | if (symbol_names[i] != NULL) |
| 1427 | log->Printf ("\"%s\"%c ", symbol_names[i], sep); |
| 1428 | else |
| 1429 | log->Printf ("\"<NULL>\"%c ", sep); |
| 1430 | |
| 1431 | } |
| 1432 | log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask, sb_bp.get()); |
| 1433 | } |
| 1434 | |
| 1435 | return sb_bp; |
| 1436 | } |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1437 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1438 | SBBreakpoint |
| 1439 | SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name) |
| 1440 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1441 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1442 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1443 | SBBreakpoint sb_bp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1444 | TargetSP target_sp(GetSP()); |
| 1445 | if (target_sp && symbol_name_regex && symbol_name_regex[0]) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1446 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1447 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1448 | RegularExpression regexp(symbol_name_regex); |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1449 | const bool internal = false; |
| 1450 | const LazyBool skip_prologue = eLazyBoolCalculate; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1451 | |
| 1452 | if (module_name && module_name[0]) |
| 1453 | { |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1454 | FileSpecList module_spec_list; |
| 1455 | module_spec_list.Append (FileSpec (module_name, false)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1456 | |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1457 | *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1458 | } |
| 1459 | else |
| 1460 | { |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1461 | *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1462 | } |
| 1463 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1464 | |
| 1465 | if (log) |
| 1466 | { |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1467 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1468 | target_sp.get(), symbol_name_regex, module_name, sb_bp.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1469 | } |
| 1470 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1471 | return sb_bp; |
| 1472 | } |
| 1473 | |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1474 | lldb::SBBreakpoint |
| 1475 | SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, |
| 1476 | const SBFileSpecList &module_list, |
| 1477 | const SBFileSpecList &comp_unit_list) |
| 1478 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1479 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1480 | |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1481 | SBBreakpoint sb_bp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1482 | TargetSP target_sp(GetSP()); |
| 1483 | if (target_sp && symbol_name_regex && symbol_name_regex[0]) |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1484 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1485 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1486 | RegularExpression regexp(symbol_name_regex); |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1487 | const bool internal = false; |
| 1488 | const LazyBool skip_prologue = eLazyBoolCalculate; |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1489 | |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1490 | *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | if (log) |
| 1494 | { |
| 1495 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1496 | target_sp.get(), symbol_name_regex, sb_bp.get()); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | return sb_bp; |
| 1500 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1501 | |
| 1502 | SBBreakpoint |
| 1503 | SBTarget::BreakpointCreateByAddress (addr_t address) |
| 1504 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1505 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1506 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1507 | SBBreakpoint sb_bp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1508 | TargetSP target_sp(GetSP()); |
| 1509 | if (target_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1510 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1511 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1512 | *sb_bp = target_sp->CreateBreakpoint (address, false); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1513 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1514 | |
| 1515 | if (log) |
| 1516 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1517 | log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)", target_sp.get(), (uint64_t) address, sb_bp.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1518 | } |
| 1519 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1520 | return sb_bp; |
| 1521 | } |
| 1522 | |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1523 | lldb::SBBreakpoint |
| 1524 | SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name) |
| 1525 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1526 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1527 | |
| 1528 | SBBreakpoint sb_bp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1529 | TargetSP target_sp(GetSP()); |
| 1530 | if (target_sp && source_regex && source_regex[0]) |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1531 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1532 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1533 | RegularExpression regexp(source_regex); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1534 | FileSpecList source_file_spec_list; |
| 1535 | source_file_spec_list.Append (source_file.ref()); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1536 | |
| 1537 | if (module_name && module_name[0]) |
| 1538 | { |
| 1539 | FileSpecList module_spec_list; |
| 1540 | module_spec_list.Append (FileSpec (module_name, false)); |
| 1541 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1542 | *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1543 | } |
| 1544 | else |
| 1545 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1546 | *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1547 | } |
| 1548 | } |
| 1549 | |
| 1550 | if (log) |
| 1551 | { |
| 1552 | char path[PATH_MAX]; |
| 1553 | source_file->GetPath (path, sizeof(path)); |
| 1554 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1555 | target_sp.get(), source_regex, path, module_name, sb_bp.get()); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | return sb_bp; |
| 1559 | } |
| 1560 | |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1561 | lldb::SBBreakpoint |
| 1562 | SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, |
| 1563 | const SBFileSpecList &module_list, |
| 1564 | const lldb::SBFileSpecList &source_file_list) |
| 1565 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1566 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1567 | |
| 1568 | SBBreakpoint sb_bp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1569 | TargetSP target_sp(GetSP()); |
| 1570 | if (target_sp && source_regex && source_regex[0]) |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1571 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1572 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1573 | RegularExpression regexp(source_regex); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1574 | *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | if (log) |
| 1578 | { |
| 1579 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1580 | target_sp.get(), source_regex, sb_bp.get()); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | return sb_bp; |
| 1584 | } |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1585 | |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1586 | lldb::SBBreakpoint |
| 1587 | SBTarget::BreakpointCreateForException (lldb::LanguageType language, |
| 1588 | bool catch_bp, |
| 1589 | bool throw_bp) |
| 1590 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1591 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1592 | |
| 1593 | SBBreakpoint sb_bp; |
| 1594 | TargetSP target_sp(GetSP()); |
| 1595 | if (target_sp) |
| 1596 | { |
| 1597 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1598 | *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp); |
| 1599 | } |
| 1600 | |
| 1601 | if (log) |
| 1602 | { |
| 1603 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)", |
| 1604 | target_sp.get(), |
| 1605 | LanguageRuntime::GetNameForLanguageType(language), |
| 1606 | catch_bp ? "on" : "off", |
| 1607 | throw_bp ? "on" : "off", |
| 1608 | sb_bp.get()); |
| 1609 | } |
| 1610 | |
| 1611 | return sb_bp; |
| 1612 | } |
| 1613 | |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 1614 | uint32_t |
| 1615 | SBTarget::GetNumBreakpoints () const |
| 1616 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1617 | TargetSP target_sp(GetSP()); |
| 1618 | if (target_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1619 | { |
| 1620 | // The breakpoint list is thread safe, no need to lock |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1621 | return target_sp->GetBreakpointList().GetSize(); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1622 | } |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 1623 | return 0; |
| 1624 | } |
| 1625 | |
| 1626 | SBBreakpoint |
| 1627 | SBTarget::GetBreakpointAtIndex (uint32_t idx) const |
| 1628 | { |
| 1629 | SBBreakpoint sb_breakpoint; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1630 | TargetSP target_sp(GetSP()); |
| 1631 | if (target_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1632 | { |
| 1633 | // The breakpoint list is thread safe, no need to lock |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1634 | *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1635 | } |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 1636 | return sb_breakpoint; |
| 1637 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1638 | |
| 1639 | bool |
| 1640 | SBTarget::BreakpointDelete (break_id_t bp_id) |
| 1641 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1642 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1643 | |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1644 | bool result = false; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1645 | TargetSP target_sp(GetSP()); |
| 1646 | if (target_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1647 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1648 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1649 | result = target_sp->RemoveBreakpointByID (bp_id); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1650 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1651 | |
| 1652 | if (log) |
| 1653 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1654 | log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | return result; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1660 | SBBreakpoint |
| 1661 | SBTarget::FindBreakpointByID (break_id_t bp_id) |
| 1662 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1663 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1664 | |
| 1665 | SBBreakpoint sb_breakpoint; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1666 | TargetSP target_sp(GetSP()); |
| 1667 | if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1668 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1669 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1670 | *sb_breakpoint = target_sp->GetBreakpointByID (bp_id); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | if (log) |
| 1674 | { |
| 1675 | log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1676 | target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get()); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | return sb_breakpoint; |
| 1680 | } |
| 1681 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1682 | bool |
| 1683 | SBTarget::EnableAllBreakpoints () |
| 1684 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1685 | TargetSP target_sp(GetSP()); |
| 1686 | if (target_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1687 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1688 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1689 | target_sp->EnableAllBreakpoints (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1690 | return true; |
| 1691 | } |
| 1692 | return false; |
| 1693 | } |
| 1694 | |
| 1695 | bool |
| 1696 | SBTarget::DisableAllBreakpoints () |
| 1697 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1698 | TargetSP target_sp(GetSP()); |
| 1699 | if (target_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1700 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1701 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1702 | target_sp->DisableAllBreakpoints (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1703 | return true; |
| 1704 | } |
| 1705 | return false; |
| 1706 | } |
| 1707 | |
| 1708 | bool |
| 1709 | SBTarget::DeleteAllBreakpoints () |
| 1710 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1711 | TargetSP target_sp(GetSP()); |
| 1712 | if (target_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1713 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1714 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1715 | target_sp->RemoveAllBreakpoints (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1716 | return true; |
| 1717 | } |
| 1718 | return false; |
| 1719 | } |
| 1720 | |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1721 | uint32_t |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1722 | SBTarget::GetNumWatchpoints () const |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1723 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1724 | TargetSP target_sp(GetSP()); |
| 1725 | if (target_sp) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1726 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1727 | // The watchpoint list is thread safe, no need to lock |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1728 | return target_sp->GetWatchpointList().GetSize(); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1729 | } |
| 1730 | return 0; |
| 1731 | } |
| 1732 | |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1733 | SBWatchpoint |
| 1734 | SBTarget::GetWatchpointAtIndex (uint32_t idx) const |
Johnny Chen | 9d954d8 | 2011-09-27 20:29:45 +0000 | [diff] [blame] | 1735 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1736 | SBWatchpoint sb_watchpoint; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1737 | TargetSP target_sp(GetSP()); |
| 1738 | if (target_sp) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1739 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1740 | // The watchpoint list is thread safe, no need to lock |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1741 | sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx)); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1742 | } |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1743 | return sb_watchpoint; |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | bool |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1747 | SBTarget::DeleteWatchpoint (watch_id_t wp_id) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1748 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1749 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1750 | |
| 1751 | bool result = false; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1752 | TargetSP target_sp(GetSP()); |
| 1753 | if (target_sp) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1754 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1755 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Johnny Chen | 7385a5a | 2012-05-31 22:56:36 +0000 | [diff] [blame] | 1756 | Mutex::Locker locker; |
| 1757 | target_sp->GetWatchpointList().GetListMutex(locker); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1758 | result = target_sp->RemoveWatchpointByID (wp_id); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | if (log) |
| 1762 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1763 | log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | return result; |
| 1767 | } |
| 1768 | |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1769 | SBWatchpoint |
| 1770 | SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1771 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1772 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1773 | |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1774 | SBWatchpoint sb_watchpoint; |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1775 | lldb::WatchpointSP watchpoint_sp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1776 | TargetSP target_sp(GetSP()); |
| 1777 | if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1778 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1779 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Johnny Chen | 7385a5a | 2012-05-31 22:56:36 +0000 | [diff] [blame] | 1780 | Mutex::Locker locker; |
| 1781 | target_sp->GetWatchpointList().GetListMutex(locker); |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1782 | watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id); |
| 1783 | sb_watchpoint.SetSP (watchpoint_sp); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | if (log) |
| 1787 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1788 | log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)", |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1789 | target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get()); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1790 | } |
| 1791 | |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1792 | return sb_watchpoint; |
| 1793 | } |
| 1794 | |
| 1795 | lldb::SBWatchpoint |
Johnny Chen | b90827e | 2012-06-04 23:19:54 +0000 | [diff] [blame] | 1796 | SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error) |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1797 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1798 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1799 | |
| 1800 | SBWatchpoint sb_watchpoint; |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1801 | lldb::WatchpointSP watchpoint_sp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1802 | TargetSP target_sp(GetSP()); |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1803 | if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0) |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1804 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1805 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1806 | uint32_t watch_type = 0; |
| 1807 | if (read) |
| 1808 | watch_type |= LLDB_WATCH_TYPE_READ; |
| 1809 | if (write) |
| 1810 | watch_type |= LLDB_WATCH_TYPE_WRITE; |
Jim Ingham | c646231 | 2013-06-18 21:52:48 +0000 | [diff] [blame] | 1811 | if (watch_type == 0) |
| 1812 | { |
| 1813 | error.SetErrorString("Can't create a watchpoint that is neither read nor write."); |
| 1814 | return sb_watchpoint; |
| 1815 | } |
| 1816 | |
Johnny Chen | 7385a5a | 2012-05-31 22:56:36 +0000 | [diff] [blame] | 1817 | // Target::CreateWatchpoint() is thread safe. |
Johnny Chen | b90827e | 2012-06-04 23:19:54 +0000 | [diff] [blame] | 1818 | Error cw_error; |
Jim Ingham | a7dfb66 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 1819 | // This API doesn't take in a type, so we can't figure out what it is. |
| 1820 | ClangASTType *type = NULL; |
| 1821 | watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error); |
Johnny Chen | b90827e | 2012-06-04 23:19:54 +0000 | [diff] [blame] | 1822 | error.SetError(cw_error); |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1823 | sb_watchpoint.SetSP (watchpoint_sp); |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | if (log) |
| 1827 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1828 | log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)", |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1829 | target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get()); |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | return sb_watchpoint; |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | bool |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1836 | SBTarget::EnableAllWatchpoints () |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1837 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1838 | TargetSP target_sp(GetSP()); |
| 1839 | if (target_sp) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1840 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1841 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Johnny Chen | 7385a5a | 2012-05-31 22:56:36 +0000 | [diff] [blame] | 1842 | Mutex::Locker locker; |
| 1843 | target_sp->GetWatchpointList().GetListMutex(locker); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1844 | target_sp->EnableAllWatchpoints (); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1845 | return true; |
| 1846 | } |
| 1847 | return false; |
| 1848 | } |
| 1849 | |
| 1850 | bool |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1851 | SBTarget::DisableAllWatchpoints () |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1852 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1853 | TargetSP target_sp(GetSP()); |
| 1854 | if (target_sp) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1855 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1856 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Johnny Chen | 7385a5a | 2012-05-31 22:56:36 +0000 | [diff] [blame] | 1857 | Mutex::Locker locker; |
| 1858 | target_sp->GetWatchpointList().GetListMutex(locker); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1859 | target_sp->DisableAllWatchpoints (); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1860 | return true; |
| 1861 | } |
| 1862 | return false; |
| 1863 | } |
| 1864 | |
| 1865 | bool |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1866 | SBTarget::DeleteAllWatchpoints () |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1867 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1868 | TargetSP target_sp(GetSP()); |
| 1869 | if (target_sp) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1870 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1871 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Johnny Chen | 7385a5a | 2012-05-31 22:56:36 +0000 | [diff] [blame] | 1872 | Mutex::Locker locker; |
| 1873 | target_sp->GetWatchpointList().GetListMutex(locker); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1874 | target_sp->RemoveAllWatchpoints (); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1875 | return true; |
| 1876 | } |
| 1877 | return false; |
| 1878 | } |
| 1879 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1880 | |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1881 | lldb::SBModule |
| 1882 | SBTarget::AddModule (const char *path, |
| 1883 | const char *triple, |
| 1884 | const char *uuid_cstr) |
| 1885 | { |
Greg Clayton | b210aec | 2012-04-23 20:23:39 +0000 | [diff] [blame] | 1886 | return AddModule (path, triple, uuid_cstr, NULL); |
| 1887 | } |
| 1888 | |
| 1889 | lldb::SBModule |
| 1890 | SBTarget::AddModule (const char *path, |
| 1891 | const char *triple, |
| 1892 | const char *uuid_cstr, |
| 1893 | const char *symfile) |
| 1894 | { |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1895 | lldb::SBModule sb_module; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1896 | TargetSP target_sp(GetSP()); |
| 1897 | if (target_sp) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1898 | { |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1899 | ModuleSpec module_spec; |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1900 | if (path) |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1901 | module_spec.GetFileSpec().SetFile(path, false); |
Greg Clayton | b210aec | 2012-04-23 20:23:39 +0000 | [diff] [blame] | 1902 | |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1903 | if (uuid_cstr) |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 1904 | module_spec.GetUUID().SetFromCString(uuid_cstr); |
Greg Clayton | b210aec | 2012-04-23 20:23:39 +0000 | [diff] [blame] | 1905 | |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1906 | if (triple) |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1907 | module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get()); |
Greg Clayton | b210aec | 2012-04-23 20:23:39 +0000 | [diff] [blame] | 1908 | |
| 1909 | if (symfile) |
| 1910 | module_spec.GetSymbolFileSpec ().SetFile(symfile, false); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1911 | |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1912 | sb_module.SetSP(target_sp->GetSharedModule (module_spec)); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1913 | } |
| 1914 | return sb_module; |
| 1915 | } |
| 1916 | |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame^] | 1917 | lldb::SBModule |
| 1918 | SBTarget::AddModule (const SBModuleSpec &module_spec) |
| 1919 | { |
| 1920 | lldb::SBModule sb_module; |
| 1921 | TargetSP target_sp(GetSP()); |
| 1922 | if (target_sp) |
| 1923 | sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap)); |
| 1924 | return sb_module; |
| 1925 | } |
| 1926 | |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1927 | bool |
| 1928 | SBTarget::AddModule (lldb::SBModule &module) |
| 1929 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1930 | TargetSP target_sp(GetSP()); |
| 1931 | if (target_sp) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1932 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1933 | target_sp->GetImages().AppendIfNeeded (module.GetSP()); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1934 | return true; |
| 1935 | } |
| 1936 | return false; |
| 1937 | } |
| 1938 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1939 | uint32_t |
| 1940 | SBTarget::GetNumModules () const |
| 1941 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1942 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1943 | |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1944 | uint32_t num = 0; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1945 | TargetSP target_sp(GetSP()); |
| 1946 | if (target_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1947 | { |
| 1948 | // The module list is thread safe, no need to lock |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1949 | num = target_sp->GetImages().GetSize(); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1950 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1951 | |
| 1952 | if (log) |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1953 | log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1954 | |
| 1955 | return num; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1956 | } |
| 1957 | |
Greg Clayton | 48e4254 | 2010-07-30 20:12:55 +0000 | [diff] [blame] | 1958 | void |
| 1959 | SBTarget::Clear () |
| 1960 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1961 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1962 | |
| 1963 | if (log) |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 1964 | log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1965 | |
Greg Clayton | 48e4254 | 2010-07-30 20:12:55 +0000 | [diff] [blame] | 1966 | m_opaque_sp.reset(); |
| 1967 | } |
| 1968 | |
| 1969 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1970 | SBModule |
| 1971 | SBTarget::FindModule (const SBFileSpec &sb_file_spec) |
| 1972 | { |
| 1973 | SBModule sb_module; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1974 | TargetSP target_sp(GetSP()); |
| 1975 | if (target_sp && sb_file_spec.IsValid()) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1976 | { |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1977 | ModuleSpec module_spec(*sb_file_spec); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1978 | // The module list is thread safe, no need to lock |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1979 | sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec)); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1980 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1981 | return sb_module; |
| 1982 | } |
| 1983 | |
Greg Clayton | 13d1950 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 1984 | lldb::ByteOrder |
| 1985 | SBTarget::GetByteOrder () |
| 1986 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1987 | TargetSP target_sp(GetSP()); |
| 1988 | if (target_sp) |
| 1989 | return target_sp->GetArchitecture().GetByteOrder(); |
Greg Clayton | 13d1950 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 1990 | return eByteOrderInvalid; |
| 1991 | } |
| 1992 | |
| 1993 | const char * |
| 1994 | SBTarget::GetTriple () |
| 1995 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1996 | TargetSP target_sp(GetSP()); |
| 1997 | if (target_sp) |
Greg Clayton | 13d1950 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 1998 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1999 | std::string triple (target_sp->GetArchitecture().GetTriple().str()); |
Greg Clayton | 13d1950 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 2000 | // Unique the string so we don't run into ownership issues since |
| 2001 | // the const strings put the string into the string pool once and |
| 2002 | // the strings never comes out |
| 2003 | ConstString const_triple (triple.c_str()); |
| 2004 | return const_triple.GetCString(); |
| 2005 | } |
| 2006 | return NULL; |
| 2007 | } |
| 2008 | |
| 2009 | uint32_t |
| 2010 | SBTarget::GetAddressByteSize() |
| 2011 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2012 | TargetSP target_sp(GetSP()); |
| 2013 | if (target_sp) |
| 2014 | return target_sp->GetArchitecture().GetAddressByteSize(); |
Greg Clayton | 13d1950 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 2015 | return sizeof(void*); |
| 2016 | } |
| 2017 | |
| 2018 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2019 | SBModule |
| 2020 | SBTarget::GetModuleAtIndex (uint32_t idx) |
| 2021 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2022 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2023 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2024 | SBModule sb_module; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2025 | ModuleSP module_sp; |
| 2026 | TargetSP target_sp(GetSP()); |
| 2027 | if (target_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 2028 | { |
| 2029 | // The module list is thread safe, no need to lock |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2030 | module_sp = target_sp->GetImages().GetModuleAtIndex(idx); |
| 2031 | sb_module.SetSP (module_sp); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 2032 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2033 | |
| 2034 | if (log) |
| 2035 | { |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 2036 | log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2037 | target_sp.get(), idx, module_sp.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2040 | return sb_module; |
| 2041 | } |
| 2042 | |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2043 | bool |
| 2044 | SBTarget::RemoveModule (lldb::SBModule module) |
| 2045 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2046 | TargetSP target_sp(GetSP()); |
| 2047 | if (target_sp) |
| 2048 | return target_sp->GetImages().Remove(module.GetSP()); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2049 | return false; |
| 2050 | } |
| 2051 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2052 | |
| 2053 | SBBroadcaster |
| 2054 | SBTarget::GetBroadcaster () const |
| 2055 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2056 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2057 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2058 | TargetSP target_sp(GetSP()); |
| 2059 | SBBroadcaster broadcaster(target_sp.get(), false); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2060 | |
| 2061 | if (log) |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 2062 | log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2063 | target_sp.get(), broadcaster.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2064 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2065 | return broadcaster; |
| 2066 | } |
| 2067 | |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 2068 | bool |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2069 | SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 2070 | { |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 2071 | Stream &strm = description.ref(); |
| 2072 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2073 | TargetSP target_sp(GetSP()); |
| 2074 | if (target_sp) |
Caroline Tice | 201a885 | 2010-09-20 16:21:41 +0000 | [diff] [blame] | 2075 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2076 | target_sp->Dump (&strm, description_level); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2077 | } |
| 2078 | else |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 2079 | strm.PutCString ("No value"); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2080 | |
| 2081 | return true; |
| 2082 | } |
| 2083 | |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 2084 | lldb::SBSymbolContextList |
| 2085 | SBTarget::FindFunctions (const char *name, uint32_t name_type_mask) |
Greg Clayton | fe356d3 | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 2086 | { |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 2087 | lldb::SBSymbolContextList sb_sc_list; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2088 | if (name && name[0]) |
Greg Clayton | fe356d3 | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 2089 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2090 | TargetSP target_sp(GetSP()); |
| 2091 | if (target_sp) |
| 2092 | { |
| 2093 | const bool symbols_ok = true; |
Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 2094 | const bool inlines_ok = true; |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 2095 | const bool append = true; |
| 2096 | target_sp->GetImages().FindFunctions (ConstString(name), |
| 2097 | name_type_mask, |
Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 2098 | symbols_ok, |
| 2099 | inlines_ok, |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 2100 | append, |
| 2101 | *sb_sc_list); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2102 | } |
Greg Clayton | fe356d3 | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 2103 | } |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 2104 | return sb_sc_list; |
Greg Clayton | fe356d3 | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 2105 | } |
| 2106 | |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2107 | lldb::SBType |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2108 | SBTarget::FindFirstType (const char* typename_cstr) |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2109 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2110 | TargetSP target_sp(GetSP()); |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2111 | if (typename_cstr && typename_cstr[0] && target_sp) |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2112 | { |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2113 | ConstString const_typename(typename_cstr); |
| 2114 | SymbolContext sc; |
| 2115 | const bool exact_match = false; |
| 2116 | |
| 2117 | const ModuleList &module_list = target_sp->GetImages(); |
| 2118 | size_t count = module_list.GetSize(); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2119 | for (size_t idx = 0; idx < count; idx++) |
| 2120 | { |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2121 | ModuleSP module_sp (module_list.GetModuleAtIndex(idx)); |
| 2122 | if (module_sp) |
| 2123 | { |
| 2124 | TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match)); |
| 2125 | if (type_sp) |
| 2126 | return SBType(type_sp); |
| 2127 | } |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2128 | } |
Sean Callanan | 7be70e8 | 2012-12-19 23:05:01 +0000 | [diff] [blame] | 2129 | |
| 2130 | // Didn't find the type in the symbols; try the Objective-C runtime |
| 2131 | // if one is installed |
| 2132 | |
| 2133 | ProcessSP process_sp(target_sp->GetProcessSP()); |
| 2134 | |
| 2135 | if (process_sp) |
| 2136 | { |
| 2137 | ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime(); |
| 2138 | |
| 2139 | if (objc_language_runtime) |
| 2140 | { |
| 2141 | TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor(); |
| 2142 | |
| 2143 | if (objc_type_vendor) |
| 2144 | { |
| 2145 | std::vector <ClangASTType> types; |
| 2146 | |
| 2147 | if (objc_type_vendor->FindTypes(const_typename, true, 1, types) > 0) |
| 2148 | return SBType(types[0]); |
| 2149 | } |
| 2150 | } |
| 2151 | } |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2152 | |
| 2153 | // No matches, search for basic typename matches |
| 2154 | ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext(); |
| 2155 | if (clang_ast) |
| 2156 | return SBType (ClangASTType::GetBasicType (clang_ast->getASTContext(), const_typename)); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2157 | } |
| 2158 | return SBType(); |
| 2159 | } |
| 2160 | |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2161 | SBType |
| 2162 | SBTarget::GetBasicType(lldb::BasicType type) |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2163 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2164 | TargetSP target_sp(GetSP()); |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2165 | if (target_sp) |
| 2166 | { |
| 2167 | ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext(); |
| 2168 | if (clang_ast) |
| 2169 | return SBType (ClangASTType::GetBasicType (clang_ast->getASTContext(), type)); |
| 2170 | } |
| 2171 | return SBType(); |
| 2172 | } |
| 2173 | |
| 2174 | |
| 2175 | lldb::SBTypeList |
| 2176 | SBTarget::FindTypes (const char* typename_cstr) |
| 2177 | { |
| 2178 | SBTypeList sb_type_list; |
| 2179 | TargetSP target_sp(GetSP()); |
| 2180 | if (typename_cstr && typename_cstr[0] && target_sp) |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2181 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2182 | ModuleList& images = target_sp->GetImages(); |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2183 | ConstString const_typename(typename_cstr); |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 2184 | bool exact_match = false; |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2185 | SymbolContext sc; |
| 2186 | TypeList type_list; |
| 2187 | |
Greg Clayton | 29399a2 | 2012-04-06 17:41:13 +0000 | [diff] [blame] | 2188 | uint32_t num_matches = images.FindTypes (sc, |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2189 | const_typename, |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 2190 | exact_match, |
| 2191 | UINT32_MAX, |
| 2192 | type_list); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2193 | |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2194 | if (num_matches > 0) |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2195 | { |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2196 | for (size_t idx = 0; idx < num_matches; idx++) |
| 2197 | { |
| 2198 | TypeSP type_sp (type_list.GetTypeAtIndex(idx)); |
| 2199 | if (type_sp) |
| 2200 | sb_type_list.Append(SBType(type_sp)); |
| 2201 | } |
| 2202 | } |
Sean Callanan | 7be70e8 | 2012-12-19 23:05:01 +0000 | [diff] [blame] | 2203 | |
| 2204 | // Try the Objective-C runtime if one is installed |
| 2205 | |
| 2206 | ProcessSP process_sp(target_sp->GetProcessSP()); |
| 2207 | |
| 2208 | if (process_sp) |
| 2209 | { |
| 2210 | ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime(); |
| 2211 | |
| 2212 | if (objc_language_runtime) |
| 2213 | { |
| 2214 | TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor(); |
| 2215 | |
| 2216 | if (objc_type_vendor) |
| 2217 | { |
| 2218 | std::vector <ClangASTType> types; |
| 2219 | |
| 2220 | if (objc_type_vendor->FindTypes(const_typename, true, UINT32_MAX, types)) |
| 2221 | { |
| 2222 | for (ClangASTType &type : types) |
| 2223 | { |
| 2224 | sb_type_list.Append(SBType(type)); |
| 2225 | } |
| 2226 | } |
| 2227 | } |
| 2228 | } |
| 2229 | } |
| 2230 | |
| 2231 | if (sb_type_list.GetSize() == 0) |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2232 | { |
| 2233 | // No matches, search for basic typename matches |
| 2234 | ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext(); |
| 2235 | if (clang_ast) |
| 2236 | sb_type_list.Append (SBType (ClangASTType::GetBasicType (clang_ast->getASTContext(), const_typename))); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2237 | } |
| 2238 | } |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2239 | return sb_type_list; |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2240 | } |
| 2241 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 2242 | SBValueList |
| 2243 | SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches) |
| 2244 | { |
| 2245 | SBValueList sb_value_list; |
| 2246 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2247 | TargetSP target_sp(GetSP()); |
| 2248 | if (name && target_sp) |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 2249 | { |
| 2250 | VariableList variable_list; |
| 2251 | const bool append = true; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2252 | const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name), |
| 2253 | append, |
| 2254 | max_matches, |
| 2255 | variable_list); |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 2256 | |
| 2257 | if (match_count > 0) |
| 2258 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2259 | ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get(); |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 2260 | if (exe_scope == NULL) |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2261 | exe_scope = target_sp.get(); |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 2262 | for (uint32_t i=0; i<match_count; ++i) |
| 2263 | { |
| 2264 | lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i))); |
| 2265 | if (valobj_sp) |
Enrico Granata | 85425d7 | 2013-02-07 18:23:56 +0000 | [diff] [blame] | 2266 | sb_value_list.Append(SBValue(valobj_sp)); |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 2267 | } |
| 2268 | } |
| 2269 | } |
| 2270 | |
| 2271 | return sb_value_list; |
| 2272 | } |
| 2273 | |
Enrico Granata | bcd80b4 | 2013-01-16 18:53:52 +0000 | [diff] [blame] | 2274 | lldb::SBValue |
| 2275 | SBTarget::FindFirstGlobalVariable (const char* name) |
| 2276 | { |
| 2277 | SBValueList sb_value_list(FindGlobalVariables(name, 1)); |
| 2278 | if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0) |
| 2279 | return sb_value_list.GetValueAtIndex(0); |
| 2280 | return SBValue(); |
| 2281 | } |
| 2282 | |
Jim Ingham | e37d605 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 2283 | SBSourceManager |
| 2284 | SBTarget::GetSourceManager() |
| 2285 | { |
| 2286 | SBSourceManager source_manager (*this); |
| 2287 | return source_manager; |
| 2288 | } |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2289 | |
Sean Callanan | 50952e9 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 2290 | lldb::SBInstructionList |
Greg Clayton | 9c76611 | 2012-03-06 22:24:44 +0000 | [diff] [blame] | 2291 | SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count) |
| 2292 | { |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 2293 | return ReadInstructions (base_addr, count, NULL); |
| 2294 | } |
| 2295 | |
| 2296 | lldb::SBInstructionList |
| 2297 | SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string) |
| 2298 | { |
Greg Clayton | 9c76611 | 2012-03-06 22:24:44 +0000 | [diff] [blame] | 2299 | SBInstructionList sb_instructions; |
| 2300 | |
| 2301 | TargetSP target_sp(GetSP()); |
| 2302 | if (target_sp) |
| 2303 | { |
| 2304 | Address *addr_ptr = base_addr.get(); |
| 2305 | |
| 2306 | if (addr_ptr) |
| 2307 | { |
| 2308 | DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0); |
| 2309 | bool prefer_file_cache = false; |
| 2310 | lldb_private::Error error; |
Greg Clayton | 3faf47c | 2013-03-28 23:42:53 +0000 | [diff] [blame] | 2311 | lldb::addr_t load_addr = LLDB_INVALID_ADDRESS; |
| 2312 | const size_t bytes_read = target_sp->ReadMemory(*addr_ptr, |
| 2313 | prefer_file_cache, |
| 2314 | data.GetBytes(), |
| 2315 | data.GetByteSize(), |
| 2316 | error, |
| 2317 | &load_addr); |
| 2318 | const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS; |
Greg Clayton | 9c76611 | 2012-03-06 22:24:44 +0000 | [diff] [blame] | 2319 | sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(), |
| 2320 | NULL, |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 2321 | flavor_string, |
Greg Clayton | 9c76611 | 2012-03-06 22:24:44 +0000 | [diff] [blame] | 2322 | *addr_ptr, |
| 2323 | data.GetBytes(), |
| 2324 | bytes_read, |
Greg Clayton | 3faf47c | 2013-03-28 23:42:53 +0000 | [diff] [blame] | 2325 | count, |
| 2326 | data_from_file)); |
Greg Clayton | 9c76611 | 2012-03-06 22:24:44 +0000 | [diff] [blame] | 2327 | } |
| 2328 | } |
| 2329 | |
| 2330 | return sb_instructions; |
| 2331 | |
| 2332 | } |
| 2333 | |
| 2334 | lldb::SBInstructionList |
Sean Callanan | 50952e9 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 2335 | SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size) |
| 2336 | { |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 2337 | return GetInstructionsWithFlavor (base_addr, NULL, buf, size); |
| 2338 | } |
| 2339 | |
| 2340 | lldb::SBInstructionList |
| 2341 | SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size) |
| 2342 | { |
Sean Callanan | 50952e9 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 2343 | SBInstructionList sb_instructions; |
| 2344 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2345 | TargetSP target_sp(GetSP()); |
| 2346 | if (target_sp) |
Sean Callanan | 50952e9 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 2347 | { |
| 2348 | Address addr; |
| 2349 | |
| 2350 | if (base_addr.get()) |
| 2351 | addr = *base_addr.get(); |
| 2352 | |
Greg Clayton | 3faf47c | 2013-03-28 23:42:53 +0000 | [diff] [blame] | 2353 | const bool data_from_file = true; |
| 2354 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2355 | sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(), |
Sean Callanan | 50952e9 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 2356 | NULL, |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 2357 | flavor_string, |
Sean Callanan | 50952e9 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 2358 | addr, |
| 2359 | buf, |
Greg Clayton | 3faf47c | 2013-03-28 23:42:53 +0000 | [diff] [blame] | 2360 | size, |
| 2361 | UINT32_MAX, |
| 2362 | data_from_file)); |
Sean Callanan | 50952e9 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | return sb_instructions; |
| 2366 | } |
| 2367 | |
| 2368 | lldb::SBInstructionList |
| 2369 | SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size) |
| 2370 | { |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 2371 | return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size); |
| 2372 | } |
| 2373 | |
| 2374 | lldb::SBInstructionList |
| 2375 | SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size) |
| 2376 | { |
| 2377 | return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size); |
Sean Callanan | 50952e9 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 2378 | } |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2379 | |
| 2380 | SBError |
| 2381 | SBTarget::SetSectionLoadAddress (lldb::SBSection section, |
| 2382 | lldb::addr_t section_base_addr) |
| 2383 | { |
| 2384 | SBError sb_error; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2385 | TargetSP target_sp(GetSP()); |
| 2386 | if (target_sp) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2387 | { |
| 2388 | if (!section.IsValid()) |
| 2389 | { |
| 2390 | sb_error.SetErrorStringWithFormat ("invalid section"); |
| 2391 | } |
| 2392 | else |
| 2393 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2394 | SectionSP section_sp (section.GetSP()); |
| 2395 | if (section_sp) |
| 2396 | { |
| 2397 | if (section_sp->IsThreadSpecific()) |
| 2398 | { |
| 2399 | sb_error.SetErrorString ("thread specific sections are not yet supported"); |
| 2400 | } |
| 2401 | else |
| 2402 | { |
Greg Clayton | 3c94737 | 2013-01-29 01:17:09 +0000 | [diff] [blame] | 2403 | if (target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp, section_base_addr)) |
| 2404 | { |
| 2405 | // Flush info in the process (stack frames, etc) |
| 2406 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 2407 | if (process_sp) |
| 2408 | process_sp->Flush(); |
| 2409 | } |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2410 | } |
| 2411 | } |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2412 | } |
| 2413 | } |
| 2414 | else |
| 2415 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2416 | sb_error.SetErrorString ("invalid target"); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2417 | } |
| 2418 | return sb_error; |
| 2419 | } |
| 2420 | |
| 2421 | SBError |
| 2422 | SBTarget::ClearSectionLoadAddress (lldb::SBSection section) |
| 2423 | { |
| 2424 | SBError sb_error; |
| 2425 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2426 | TargetSP target_sp(GetSP()); |
| 2427 | if (target_sp) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2428 | { |
| 2429 | if (!section.IsValid()) |
| 2430 | { |
| 2431 | sb_error.SetErrorStringWithFormat ("invalid section"); |
| 2432 | } |
| 2433 | else |
| 2434 | { |
Greg Clayton | 3c94737 | 2013-01-29 01:17:09 +0000 | [diff] [blame] | 2435 | if (target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP())) |
| 2436 | { |
| 2437 | // Flush info in the process (stack frames, etc) |
| 2438 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 2439 | if (process_sp) |
| 2440 | process_sp->Flush(); |
| 2441 | } |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2442 | } |
| 2443 | } |
| 2444 | else |
| 2445 | { |
| 2446 | sb_error.SetErrorStringWithFormat ("invalid target"); |
| 2447 | } |
| 2448 | return sb_error; |
| 2449 | } |
| 2450 | |
| 2451 | SBError |
| 2452 | SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset) |
| 2453 | { |
| 2454 | SBError sb_error; |
| 2455 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2456 | TargetSP target_sp(GetSP()); |
| 2457 | if (target_sp) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2458 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2459 | ModuleSP module_sp (module.GetSP()); |
| 2460 | if (module_sp) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2461 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2462 | bool changed = false; |
| 2463 | if (module_sp->SetLoadAddress (*target_sp, slide_offset, changed)) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2464 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2465 | // The load was successful, make sure that at least some sections |
| 2466 | // changed before we notify that our module was loaded. |
| 2467 | if (changed) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2468 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2469 | ModuleList module_list; |
| 2470 | module_list.Append(module_sp); |
| 2471 | target_sp->ModulesDidLoad (module_list); |
Greg Clayton | 3c94737 | 2013-01-29 01:17:09 +0000 | [diff] [blame] | 2472 | // Flush info in the process (stack frames, etc) |
| 2473 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 2474 | if (process_sp) |
| 2475 | process_sp->Flush(); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2476 | } |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2477 | } |
| 2478 | } |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2479 | else |
| 2480 | { |
| 2481 | sb_error.SetErrorStringWithFormat ("invalid module"); |
| 2482 | } |
| 2483 | |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2484 | } |
| 2485 | else |
| 2486 | { |
| 2487 | sb_error.SetErrorStringWithFormat ("invalid target"); |
| 2488 | } |
| 2489 | return sb_error; |
| 2490 | } |
| 2491 | |
| 2492 | SBError |
| 2493 | SBTarget::ClearModuleLoadAddress (lldb::SBModule module) |
| 2494 | { |
| 2495 | SBError sb_error; |
| 2496 | |
| 2497 | char path[PATH_MAX]; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2498 | TargetSP target_sp(GetSP()); |
| 2499 | if (target_sp) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2500 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2501 | ModuleSP module_sp (module.GetSP()); |
| 2502 | if (module_sp) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2503 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2504 | ObjectFile *objfile = module_sp->GetObjectFile(); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2505 | if (objfile) |
| 2506 | { |
| 2507 | SectionList *section_list = objfile->GetSectionList(); |
| 2508 | if (section_list) |
| 2509 | { |
Greg Clayton | 3c94737 | 2013-01-29 01:17:09 +0000 | [diff] [blame] | 2510 | bool changed = false; |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2511 | const size_t num_sections = section_list->GetSize(); |
| 2512 | for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) |
| 2513 | { |
| 2514 | SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx)); |
| 2515 | if (section_sp) |
Greg Clayton | 3c94737 | 2013-01-29 01:17:09 +0000 | [diff] [blame] | 2516 | changed |= target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp) > 0; |
| 2517 | } |
| 2518 | if (changed) |
| 2519 | { |
| 2520 | // Flush info in the process (stack frames, etc) |
| 2521 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 2522 | if (process_sp) |
| 2523 | process_sp->Flush(); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2524 | } |
| 2525 | } |
| 2526 | else |
| 2527 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2528 | module_sp->GetFileSpec().GetPath (path, sizeof(path)); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2529 | sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path); |
| 2530 | } |
| 2531 | } |
| 2532 | else |
| 2533 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2534 | module_sp->GetFileSpec().GetPath (path, sizeof(path)); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2535 | sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path); |
| 2536 | } |
| 2537 | } |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2538 | else |
| 2539 | { |
| 2540 | sb_error.SetErrorStringWithFormat ("invalid module"); |
| 2541 | } |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2542 | } |
| 2543 | else |
| 2544 | { |
| 2545 | sb_error.SetErrorStringWithFormat ("invalid target"); |
| 2546 | } |
| 2547 | return sb_error; |
| 2548 | } |
| 2549 | |
| 2550 | |
Greg Clayton | e14e192 | 2012-12-04 02:22:16 +0000 | [diff] [blame] | 2551 | lldb::SBSymbolContextList |
| 2552 | SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type) |
| 2553 | { |
| 2554 | SBSymbolContextList sb_sc_list; |
| 2555 | if (name && name[0]) |
| 2556 | { |
| 2557 | TargetSP target_sp(GetSP()); |
| 2558 | if (target_sp) |
| 2559 | { |
| 2560 | bool append = true; |
| 2561 | target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name), |
| 2562 | symbol_type, |
| 2563 | *sb_sc_list, |
| 2564 | append); |
| 2565 | } |
| 2566 | } |
| 2567 | return sb_sc_list; |
| 2568 | |
| 2569 | } |
| 2570 | |
| 2571 | |
Greg Clayton | 4b63a5c | 2013-01-04 18:10:18 +0000 | [diff] [blame] | 2572 | lldb::SBValue |
| 2573 | SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options) |
| 2574 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2575 | Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 2576 | Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Greg Clayton | 4b63a5c | 2013-01-04 18:10:18 +0000 | [diff] [blame] | 2577 | SBValue expr_result; |
| 2578 | ExecutionResults exe_results = eExecutionSetupError; |
| 2579 | ValueObjectSP expr_value_sp; |
| 2580 | TargetSP target_sp(GetSP()); |
| 2581 | StackFrame *frame = NULL; |
| 2582 | if (target_sp) |
| 2583 | { |
| 2584 | if (expr == NULL || expr[0] == '\0') |
| 2585 | { |
| 2586 | if (log) |
| 2587 | log->Printf ("SBTarget::EvaluateExpression called with an empty expression"); |
| 2588 | return expr_result; |
| 2589 | } |
| 2590 | |
| 2591 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 2592 | ExecutionContext exe_ctx (m_opaque_sp.get()); |
| 2593 | |
| 2594 | if (log) |
| 2595 | log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr); |
| 2596 | |
| 2597 | frame = exe_ctx.GetFramePtr(); |
| 2598 | Target *target = exe_ctx.GetTargetPtr(); |
| 2599 | |
| 2600 | if (target) |
| 2601 | { |
| 2602 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 2603 | StreamString frame_description; |
| 2604 | if (frame) |
| 2605 | frame->DumpUsingSettingsFormat (&frame_description); |
| 2606 | Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s", |
| 2607 | expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str()); |
| 2608 | #endif |
| 2609 | exe_results = target->EvaluateExpression (expr, |
| 2610 | frame, |
| 2611 | expr_value_sp, |
| 2612 | options.ref()); |
| 2613 | |
| 2614 | expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue()); |
| 2615 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 2616 | Host::SetCrashDescription (NULL); |
| 2617 | #endif |
| 2618 | } |
| 2619 | else |
| 2620 | { |
| 2621 | if (log) |
| 2622 | log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget."); |
| 2623 | } |
| 2624 | } |
| 2625 | #ifndef LLDB_DISABLE_PYTHON |
| 2626 | if (expr_log) |
| 2627 | expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **", |
| 2628 | expr_result.GetValue(), |
| 2629 | expr_result.GetSummary()); |
| 2630 | |
| 2631 | if (log) |
| 2632 | log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", |
| 2633 | frame, |
| 2634 | expr, |
| 2635 | expr_value_sp.get(), |
| 2636 | exe_results); |
| 2637 | #endif |
| 2638 | |
| 2639 | return expr_result; |
| 2640 | } |
| 2641 | |
Greg Clayton | 13fbb99 | 2013-02-01 00:47:49 +0000 | [diff] [blame] | 2642 | |
| 2643 | lldb::addr_t |
| 2644 | SBTarget::GetStackRedZoneSize() |
| 2645 | { |
| 2646 | TargetSP target_sp(GetSP()); |
| 2647 | if (target_sp) |
| 2648 | { |
| 2649 | ABISP abi_sp; |
| 2650 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 2651 | if (process_sp) |
| 2652 | abi_sp = process_sp->GetABI(); |
| 2653 | else |
| 2654 | abi_sp = ABI::FindPlugin(target_sp->GetArchitecture()); |
| 2655 | if (abi_sp) |
| 2656 | return abi_sp->GetRedZoneSize(); |
| 2657 | } |
| 2658 | return 0; |
| 2659 | } |
| 2660 | |