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