aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectTarget.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-07-06Refine the reporting mechanism for interruption.Jim Ingham1-10/+35
Also, make it possible for new Targets which haven't been added to the TargetList yet to check for interruption, and add a few more places in building modules where we can check for interruption. Differential Revision: https://reviews.llvm.org/D154542
2023-07-03[lldb] Remove old commented out code (NFC)Dave Lee1-22/+0
Move to `DumpAddress` in c4a8a76048e91baecb5746b80b9733e4af299937.
2023-07-03[lldb][NFCI] Target::StopHook::GetDescription should take a Stream ref ↵Alex Langford1-1/+1
instead of pointer We always assume that this is valid anyway, might as well take a reference. Differential Revision: https://reviews.llvm.org/D153917
2023-06-29Add 'target dump section-load-list' for lldb debuggingJason Molenda1-1/+27
A command to dump the Target's SectionLoadList, to debug possible issues with the table. Differential Revision: https://reviews.llvm.org/D154169
2023-06-26[lldb] Add `source cache dump` and `source cache clear` subcommandJonas Devlieghere1-2/+2
Add two new source subcommands: source cache dump and source cache clear. As the name implies the first one dumps the source cache while the later clears the cache. This patch was motivated by a handful of (internal) bug reports related to sources not being available. Right now those issues can be hard to diagnose. The new commands give users, as well as us as developers, more insight into and control over the source cache. Differential revision: https://reviews.llvm.org/D153685
2023-06-26[lldb][NFCI] UUID::Dump should take a reference instead of a pointerAlex Langford1-5/+5
We always assume the Stream pointer is valid, might as well be taking a reference instead. Differential Revision: https://reviews.llvm.org/D153710
2023-06-06[lldb/Commands] Add support to auto-completion for user commandsMed Ismail Bennani1-23/+16
This patch should allow the user to set specific auto-completion type for their custom commands. To do so, we had to hoist the `CompletionType` enum so the user can access it and add a new completion type flag to the CommandScriptAdd Command Object. So now, the user can specify which completion type will be used with their custom command, when they register it. This also makes the `crashlog` custom commands use disk-file completion type, to browse through the user file system and load the report. Differential Revision: https://reviews.llvm.org/D152011 Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-06-06[lldb/Target] Add ability to set a label to targetsMed Ismail Bennani1-10/+46
This patch add the ability for the user to set a label for a target. This can be very useful when debugging targets with the same executables in the same session. Labels can be set either at the target creation in the command interpreter or at any time using the SBAPI. Target labels show up in the `target list` output, following the target index, and they also allow the user to switch targets using them. rdar://105016191 Differential Revision: https://reviews.llvm.org/D151859 Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-05-05Re-land "[lldb] Expose a const iterator for SymbolContextList"Alex Langford1-56/+43
Re-lands 04aa943be8ed5c03092e2a90112ac638360ec253 with modifications to fix tests. I originally reverted this because it caused a test to fail on Linux. The problem was that I inverted a condition on accident.
2023-05-04Revert "[lldb] Expose a const iterator for SymbolContextList"Alex Langford1-43/+56
This reverts commit 04aa943be8ed5c03092e2a90112ac638360ec253. This broke the debian buildbot and I'm not sure why. Reverting so I can investigate.
2023-05-04[lldb] Expose a const iterator for SymbolContextListAlex Langford1-56/+43
There are many situations where we'll iterate over a SymbolContextList with the pattern: ``` SymbolContextList sc_list; // Fill in sc_list here for (auto i = 0; i < sc_list.GetSize(); i++) { SymbolContext sc; sc_list.GetSymbolAtContext(i, sc); // Do work with sc } ``` Adding an iterator to iterate over the instances directly means we don't have to do bounds checking or create a copy of every element of the SymbolContextList. Differential Revision: https://reviews.llvm.org/D149900
2023-05-02[lldb] Minor cleanups at callsites of FileSpec::GetFileNameExtensionAlex Langford1-1/+1
FileSpec::GetFileNameExtension returns a StringRef. In some cases we are calling it and then storing the result in a local. To prevent cases where we store the StringRef, mutate the Filespec, and then try to use the stored StringRef afterwards, I've audited the callsites and made adjustments to mitigate: Either marking the FileSpec it comes from as const (to avoid mutations) or by not storing the StringRef in a local if it makes sense not to. Differential Revision: https://reviews.llvm.org/D149671
2023-04-26[lldb] Change return type of FileSpec::GetFileNameExtensionAlex Langford1-1/+1
These don't really need to be in ConstStrings. It's nice that comparing ConstStrings is fast (just a pointer comparison) but the cost of creating the ConstString usually already includes the cost of doing a StringRef comparison anyway, so this is just extra work and extra memory consumption for basically no benefit. Differential Revision: https://reviews.llvm.org/D149300
2023-03-30[NFC] Fix potential for use-after-free in DumpModuleInfoActionMariya Podchishchaeva1-2/+5
Since each `DumpModuleInfoAction` can now contain a pointer to a `raw_ostream`, saving there a poiter that owned by a local `unique_ptr` may cause use-after-free. Clarify ownership and save a `shared_ptr` inside of `DumpModuleInfoAction` instead. Found by static analyzer. Reviewed By: tahonermann, aaron.ballman Differential Revision: https://reviews.llvm.org/D146412
2023-03-15Add a Debugger interruption mechanism in conjunction with theJim Ingham1-9/+9
Command Interpreter mechanism. Differential Revision: https://reviews.llvm.org/D145136
2023-02-09[LLDB] Add missing newline to "image lookup" outputDavid Spickett1-0/+2
When using --name, due to a missing newline, multiple symbol results were not correctly printed: ``` (lldb) image lookup -r -n "As<.*" 2 matches found in <...>/tbi_lisp: Address: tbi_lisp<...> Summary: tbi_lisp<...> at Symbol.cpp:75 Address: tbi_lisp<...> Summary: tbi_lisp<...> at Symbol.cpp:82 ``` It should be: ``` (lldb) image lookup -r -n "As<.*" 2 matches found in /home/david.spickett/tbi_lisp/tbi_lisp: Address: tbi_lisp<...> Summary: tbi_lisp<...> at Symbol.cpp:75 Address: tbi_lisp<...> Summary: tbi_lisp<...> at Symbol.cpp:82 ``` With Address/Summary on separate lines. Reviewed By: clayborg, labath Differential Revision: https://reviews.llvm.org/D143564
2023-01-10Move from llvm::makeArrayRef to ArrayRef deduction guides - last partserge-sans-paille1-7/+7
This is a follow-up to https://reviews.llvm.org/D140896, split into several parts as it touches a lot of files. Differential Revision: https://reviews.llvm.org/D141298
2022-12-19Revert "[lldb] Remove redundant .c_str() and .get() calls"Muhammad Omair Javaid1-1/+1
This reverts commit fbaf48be0ff6fb24b9aa8fe9c2284fe88a8798dd. This has broken all LLDB buildbots: https://lab.llvm.org/buildbot/#/builders/68/builds/44990 https://lab.llvm.org/buildbot/#/builders/96/builds/33160
2022-12-18[lldb] Remove redundant .c_str() and .get() callsFangrui Song1-1/+1
Removing .c_str() has a semantics difference, but the use scenarios likely do not matter as we don't have NUL in the strings.
2022-11-16Make CompilerType safeAdrian Prantl1-2/+3
When a process gets restarted TypeSystem objects associated with it may get deleted, and any CompilerType objects holding on to a reference to that type system are a use-after-free in waiting. Because of the SBAPI, we don't have tight control over where CompilerTypes go and when they are used. This is particularly a problem in the Swift plugin, where the scratch TypeSystem can be restarted while the process is still running. The Swift plugin has a lock to prevent abuse, but where there's a lock there can be bugs. This patch changes CompilerType to store a std::weak_ptr<TypeSystem>. Most of the std::weak_ptr<TypeSystem>* uglyness is hidden by introducing a wrapper class CompilerType::WrappedTypeSystem that has a dyn_cast_or_null() method. The only sites that need to know about the weak pointer implementation detail are the ones that deal with creating TypeSystems. rdar://101505232 Differential Revision: https://reviews.llvm.org/D136650
2022-10-17[lldb] Print newline between found typesArthur Eubanks1-1/+1
Or else multiple entries end up overlapping on the same line. Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D135827
2022-09-27[lldb] Improve display of absolute symbol lookupAlvin Wong1-0/+4
When running `target module lookup` command, show the name of absolute symbols. Also fix indentation issue after printing an absolute symbol. Reviewed By: clayborg, DavidSpickett Differential Revision: https://reviews.llvm.org/D134516
2022-09-27[lldb] Add newline in output of `target modules lookup`Alvin Wong1-0/+1
This adds a line break between each result address in the output of the lldb command `target modules lookup`. Before this change, a new address result will be printed on the same line as the summary of the last result, making the output difficult to view. Also adds a test for this command. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D134111
2022-08-22Don't create sections for SHN_ABS symbols in ELF files.Greg Clayton1-4/+14
Symbols that have the section index of SHN_ABS were previously creating extra top level sections that contained the value of the symbol as if the symbol's value was an address. As far as I can tell, these symbol's values are not addresses, even if they do have a size. To make matters worse, adding these extra sections can stop address lookups from succeeding if the symbol's value + size overlaps with an existing section as these sections get mapped into memory when the image is loaded by the dynamic loader. This can cause stack frames to appear empty as the address lookup fails completely. This patch: - doesn't create a section for any SHN_ABS symbols - makes symbols that are absolute have values that are not addresses - add accessors to SBSymbol to get the value and size of a symbol as raw integers. Prevoiusly there was no way to access a symbol's value from a SBSymbol because the only accessors were: SBAddress SBSymbol::GetStartAddress(); SBAddress SBSymbol::GetEndAddress(); and these accessors would return an invalid SBAddress if the symbol's value wasn't an address - Adds a test to ensure no ".absolute.<symbol-name>" sections are created - Adds a test to test the new SBSymbol APIs Differential Revision: https://reviews.llvm.org/D131705
2022-07-28[NFC] Improve FileSpec internal APIs and usage in preparation for adding ↵Greg Clayton1-3/+3
caching of resolved/absolute. Resubmission of https://reviews.llvm.org/D130309 with the 2 patches that fixed the linux buildbot, and new windows fixes. The FileSpec APIs allow users to modify instance variables directly by getting a non const reference to the directory and filename instance variables. This makes it impossible to control all of the times the FileSpec object is modified so we can clear cached member variables like m_resolved and with an upcoming patch caching if the file is relative or absolute. This patch modifies the APIs of FileSpec so no one can modify the directory or filename instance variables directly by adding set accessors and by removing the get accessors that are non const. Many clients were using FileSpec::GetCString(...) which returned a unique C string from a ConstString'ified version of the result of GetPath() which returned a std::string. This caused many locations to use this convenient function incorrectly and could cause many strings to be added to the constant string pool that didn't need to. Most clients were converted to using FileSpec::GetPath().c_str() when possible. Other clients were modified to use the newly renamed version of this function which returns an actualy ConstString: ConstString FileSpec::GetPathAsConstString(bool denormalize = true) const; This avoids the issue where people were getting an already uniqued "const char *" that came from a ConstString only to put the "const char *" back into a "ConstString" object. By returning the ConstString instead of a "const char *" clients can be more efficient with the result. The patch: - Removes the non const GetDirectory() and GetFilename() get accessors - Adds set accessors to replace the above functions: SetDirectory() and SetFilename(). - Adds ClearDirectory() and ClearFilename() to replace usage of the FileSpec::GetDirectory().Clear()/FileSpec::GetFilename().Clear() call sites - Fixed all incorrect usage of FileSpec::GetCString() to use FileSpec::GetPath().c_str() where appropriate, and updated other call sites that wanted a ConstString to use the newly returned ConstString appropriately and efficiently. Differential Revision: https://reviews.llvm.org/D130549
2022-07-23Revert "[NFC] Improve FileSpec internal APIs and usage in preparation for ↵Nico Weber1-3/+3
adding caching of resolved/absolute." and follow-ups This reverts commit 9429b67b8e300e638d7828bbcb95585f85c4df4d. It broke the build on Windows, see comments on https://reviews.llvm.org/D130309 It also reverts these follow-ups: Revert "Fix buildbot breakage after https://reviews.llvm.org/D130309." This reverts commit f959d815f4637890ebbacca379f1c38ab47e4e14. Revert "Fix buildbot breakage after https://reviews.llvm.org/D130309." This reverts commit 0bbce7a4c2d2bff622bdadd4323f93f5d90e6d24. Revert "Cache the value for absolute path in FileSpec." This reverts commit dabe877248b85b34878e75d5510339325ee087d0.
2022-07-22[NFC] Improve FileSpec internal APIs and usage in preparation for adding ↵Greg Clayton1-3/+3
caching of resolved/absolute. The FileSpect APIs allow users to modify instance variables directly by getting a non const reference to the directory and filename instance variables. This makes it impossibly to control all of the times the FileSpec object is modified so we can clear the cache. This patch modifies the APIs of FileSpec so no one can modify the directory or filename directly by adding set accessors and by removing the get accessors that are non const. Many clients were using FileSpec::GetCString(...) which returned a unique C string from a ConstString'ified version of the result of GetPath() which returned a std::string. This caused many locations to use this convenient function incorrectly and could cause many strings to be added to the constant string pool that didn't need to. Most clients were converted to using FileSpec::GetPath().c_str() when possible. Other clients were modified to use the newly renamed version of this function which returns an actualy ConstString: ConstString FileSpec::GetPathAsConstString(bool denormalize = true) const; This avoids the issue where people were getting an already uniqued "const char *" that came from a ConstString only to put the "const char *" back into a "ConstString" object. By returning the ConstString instead of a "const char *" clients can be more efficient with the result. The patch: - Removes the non const GetDirectory() and GetFilename() get accessors - Adds set accessors to replace the above functions: SetDirectory() and SetFilename(). - Adds ClearDirectory() and ClearFilename() to replace usage of the FileSpec::GetDirectory().Clear()/FileSpec::GetFilename().Clear() call sites - Fixed all incorrect usage of FileSpec::GetCString() to use FileSpec::GetPath().c_str() where appropriate, and updated other call sites that wanted a ConstString to use the newly returned ConstString appropriately and efficiently. Differential Revision: https://reviews.llvm.org/D130309
2022-07-20[LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scanSlava Gurevich1-6/+6
Improve LLDB reliability by fixing the following "uninitialized variables" static code inspection warnings from scan.coverity.com: 1094796 1095721 1095728 1095737 1095741 1095756 1095779 1095789 1095805 1214552 1229457 1232475 1274006 1274010 1293427 1364800 1364802 1364804 1364812 1364816 1374902 1374909 1384975 1399312 1420451 1431704 1454230 1454554 1454615 1454579 1454594 1454832 1457759 1458696 1461909 1467658 1487814 1487830 1487845 Differential Revision: https://reviews.llvm.org/D130098
2022-07-14[lldb] Refactor command option enum values (NFC)Jonas Devlieghere1-40/+1
Refactor the command option enum values and the command argument table to connect the two. This has two benefits: - We guarantee that two options that use the same argument type have the same accepted values. - We can print the enum values and their description in the help output. (D129707) Differential revision: https://reviews.llvm.org/D129703
2022-07-13[lldb] Add image dump pcm-info commandDave Lee1-3/+66
Add `pcm-info` to the `target module dump` subcommands. This dump command shows information about clang .pcm files. This command effectively runs `clang -module-file-info` and produces identical output. The .pcm file format is tightly coupled to the clang version. The clang embedded in lldb is not guaranteed to match the version of the clang executable available on the local system. There have been times when I've needed to view the details about a .pcm file produced by lldb's embedded clang, but because the clang executable was a slightly different version, the `-module-file-info` invocation failed. With this command, users can inspect .pcm files generated by lldb too. Differential Revision: https://reviews.llvm.org/D129456
2022-06-27Have CommandObjectParsed check for "commands that take no arguments".Jim Ingham1-22/+21
This is currently being done in an ad hoc way, and so for some commands it isn't being checked. We have the info to make this check, since commands are supposed to add their arguments to the m_arguments field of the CommandObject. This change uses that info to check whether the command received arguments in error. A handful of commands weren't defining their argument types, I also had to fix them. And a bunch of commands were checking for arguments by hand, so I removed those checks in favor of the CommandObject one. That also meant I had to change some tests that were checking for the ad hoc error outputs. Differential Revision: https://reviews.llvm.org/D128453
2022-06-22[lldb] Resolve exe location for `target create`Alvin Wong1-6/+12
This fixes an issue that, when you start lldb or use `target create` with a program name which is on $PATH, or not specify the .exe suffix of a program in the working directory on Windows, you get a confusing error, for example: (lldb) target create notepad error: 'C:\WINDOWS\SYSTEM32\notepad.exe' doesn't contain any 'host' platform architectures: i686, x86_64, i386, i386 Fixes https://github.com/mstorsjo/llvm-mingw/issues/265 Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D127436
2022-05-23[lldb] Specify aguments of `image list`Dave Lee1-2/+5
Register positional argument details in `CommandObjectTargetModulesList`. I recently learned that `image list` takes a module name, but the help info does not indicate this. With this change, `help image list` will show that it accepts zero or more module names. This makes it easier to get info about specific modules, without having to find/grep through the full image list. Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D125154
2022-05-16[lldb][NFC] Make cmd a reference in GenerateOptionUsageDavid Spickett1-1/+1
Nowhere in lldb do we call this with a null pointer. If we did, the first line of the function would fault anyway. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D125218
2022-05-12In 92eaad2dd7adb5ee92f397cef85ab11f2612294e I made it possible to runJim Ingham1-3/+22
a debug session with only a remote path to the file you are debugging using the SB API's. This patch makes it possible to do this using target create --remote-file <some_path> without supplying a local file as well. Prior to this change we errored out saying that we haven't implemented copying the binary back from the remote. I didn't implement the copy back (in the case I'm interested in - iOS debugging - we don't actually have a way for lldb to do that). This patch doesn't impede doing that, I just didn't need it. I think for some object file formats debugging w/o the binary file is hard because of what doesn't get mapped in. I didn't try to arbitrate that, I'm assuming anybody who has to do this knows what they are going to get. If there's a connected platform that can check that the remote file exists, it will do so, otherwise we trust the user's input - if it isn't there the process launch is going to fail with no-such-file so it will be pretty clear what went wrong. Differential Revision: https://reviews.llvm.org/D124947
2022-05-03[lldb] Add setting for max depth of value object printing (NFC)Dave Lee1-5/+2
This adds a setting (`target.max-children-depth`) that will provide a default value for the `--depth` flag used by `expression` and `frame variable`. The new setting uses the same default that's currently fixed in source: `UINT32_MAX`. This provides two purposes: 1. Allowing downstream forks to provide a customized default. 2. Allowing users to set their own default. Following `target.max-children-count`, a warning is emitted when the max depth is reached. The warning lets users know which flags or settings they can customize. This warning is shown only when the limit is the default value. rdar://87466495 Differential Revision: https://reviews.llvm.org/D123954
2022-04-14[lldb] Show the DBGError if dsymForUUID can't find a dSYMJonas Devlieghere1-2/+7
Show the user the DBGError (if available) when dsymForUUID fails. rdar://90949180 Differential revision: https://reviews.llvm.org/D123743
2022-03-31[LLDB] Applying clang-tidy modernize-use-equals-default over LLDBShafik Yaghmour1-3/+3
Applied modernize-use-equals-default clang-tidy check over LLDB. This check is already present in the lldb/.clang-tidy config. Differential Revision: https://reviews.llvm.org/D121844
2022-03-16[LLDB] Change enumaration to enumerationWill Hawkins1-1/+1
Change enumaration to enumeration in code handling LLDB help output. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D121800
2022-03-02[LLDB] Add error message when using --show-variable-ranges without -vZequan Wu1-0/+9
2022-03-02[LLDB] Dump valid ranges of variablesZequan Wu1-16/+29
This allows `image lookup -a ... -v` to print variables only if the given address is covered by the valid ranges of the variables. Since variables created in dwarf plugin always has empty scope range, print the variable if it has empty scope. Differential Revision: https://reviews.llvm.org/D119963
2022-03-02[lldb/Platform] Prepare decouple instance and plugin namesPavel Labath1-2/+2
This patch changes the return value of Platform::GetName() to a StringRef, and uses the opportunity (compile errors) to change some callsites to use GetPluginName() instead. The two methods still remain hardwired to return the same thing, but this will change once the ideas in <https://discourse.llvm.org/t/multiple-platforms-with-the-same-name/59594> are implemented. Differential Revision: https://reviews.llvm.org/D119146
2022-02-03[lldb] Rename Logging.h to LLDBLog.h and clean up includesPavel Labath1-0/+1
Most of our code was including Log.h even though that is not where the "lldb" log channel is defined (Log.h defines the generic logging infrastructure). This worked because Log.h included Logging.h, even though it should. After the recent refactor, it became impossible the two files include each other in this direction (the opposite inclusion is needed), so this patch removes the workaround that was put in place and cleans up all files to include the right thing. It also renames the file to LLDBLog to better reflect its purpose.
2022-02-02[lldb] Convert "LLDB" log channel to the new APIPavel Labath1-1/+1
2022-01-23[Commands] Remove redundant member initialization (NFC)Kazu Hirata1-30/+20
Identified with readability-redundant-member-init.
2022-01-15[lldb] Correctly display the number of types foundJonas Devlieghere1-2/+3
Correctly display the number of types found for `target modules lookup --type` and add a test. Fixes #53219
2021-11-01[lldb][NFC] avoid unnecessary roundtrips between different string typesXu Jun1-4/+3
The amount of roundtrips between StringRefs, ConstStrings and std::strings is getting a bit out of hand, this patch avoid the unnecessary roundtrips. Reviewed By: wallace, aprantl Differential Revision: https://reviews.llvm.org/D112863
2021-10-19[lldb] Allow dumping the state of all scratch TypeSystemsRaphael Isemann1-0/+51
This adds the `target dump typesystem'`command which dumps the TypeSystem of the target itself (aka the 'scratch TypeSystem'). This is similar to `target modules dump ast` which dumps the AST of lldb::Modules associated with a selected target. Unlike `target modules dump ast`, the new command is not a subcommand of `target modules dump` as it's not touching the modules of a target at all. Also unlike `target modules dump ast` I tried to keep the implementation language-neutral, so this patch moves our Clang `Dump` to the `TypeSystem` interface so it will also dump the state of any future/downstream scratch TypeSystems (e.g., Swift). That's also why the command just refers to a 'typesystem' instead of an 'ast' (which is only how Clang is necessarily modelling the internal TypeSystem state). The main motivation for this patch is that I need to write some tests that check for duplicates in the ScratchTypeSystemClang of a target. There is currently no way to check for this at the moment (beside measuring memory consumption of course). It's probably also useful for debugging LLDB itself. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D111936
2021-09-24Add pragma to make it easier to find "image list" implJason Molenda1-0/+1
I couldn't find it; make this easier for next time.
2021-09-21[lldb] Add --stack option to `target symbols add` commandJonas Devlieghere1-2/+70
Currently you can ask the target symbols add command to locate the debug symbols for the current frame. This patch add an options to do that for the whole call stack. Differential revision: https://reviews.llvm.org/D110011