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