summaryrefslogtreecommitdiff
path: root/lldb/source/Utility/Broadcaster.cpp
AgeCommit message (Collapse)Author
2024-07-03[lldb] Make Broadcaster mutexes non-recursive (#97400)Pavel Labath
Non-recursive mutexes encourage better locking discipline and avoid bugs like #96750, where one can unexpectedly re-enter the critical section on the same thread, and interrupt a presumed-indivisible operation. In this case, the only needed fix was to remove locking from some BroadcastManager functions, which were only called from the Listener class (and the listener already locked those mutexes to preserve lock ordering). While doing that, I noticed we don't have unit tests for these functions, so I added one.
2024-06-28[lldb] Use SmallVector::erase correctlyPavel Labath
erase() invalidates the iterator, we must use the returned iterator to continue iterating. This does not actually make a difference with the current implementation of SmallVector (erase will effectively return the same pointer), but it avoids future confusion.
2024-04-24[lldb][nfc] Move broadcaster class strings away from ConstString (#89690)Alex Langford
These are hardcoded strings that are already present in the data section of the binary, no need to immediately place them in the ConstString StringPools. Lots of code still calls `GetBroadcasterClass` and places the return value into a ConstString. Changing that would be a good follow-up. Additionally, calls to these functions are still wrapped in ConstStrings at the SBAPI layer. This is because we must guarantee the lifetime of all strings handed out publicly.
2024-01-26[lldb][NFCI] Remove EventData* parameter from BroadcastEventIfUnique (#79045)Alex Langford
Instead of passing the data to BroadcastEventIfUnique to create an Event object on the behalf of the caller, the caller can create the Event up-front.
2024-01-22[lldb][NFCI] Remove EventData* param from BroadcastEvent (#78773)Alex Langford
BroadcastEvent currently takes its EventData* param and shoves it into an Event object, which takes ownership of the pointer and places it into a shared_ptr to manage the lifetime. Instead of relying on `new` and passing raw pointers around, I think it would make more sense to create the shared_ptr up front.
2023-11-10Fix a little thinko in sending events to secondary listeners. (#71997)jimingham
If `unique` is true, I was redoing the uniqueness check for the secondary listeners, which is racy since a "duplicate" event could come in between deciding to send the event to the main listener and checking for the shadow listener, and then the two streams would get out of sync. There's not a good way to write a direct test for this, but the test_shadow_listeners test has been flakey and this is the only racy part of that system I can find. So the test would be that that test_shadow_listeners becomes not flakey.
2023-08-16Replace the singleton "ShadowListener" with a primary and N secondary ListenersJim Ingham
Before the addition of the process "Shadow Listener" you could only have one Listener observing the Process Broadcaster. That was necessary because fetching the Process event is what switches the public process state, and for the execution control logic to be manageable you needed to keep other listeners from causing this to happen before the main process control engine was ready. Ismail added the notion of a "ShadowListener" - which allowed you ONE extra process listener. This patch inverts that setup by designating the first listener as primary - and giving it priority in fetching events. Differential Revision: https://reviews.llvm.org/D157556
2023-06-07[lldb][NFCI] Change type of Broadcaster's nameAlex Langford
Broadcasters don't need their names in the StringPool. It doesn't benefit from fast comparisons and doesn't benefit from uniqueness. Differential Revision: https://reviews.llvm.org/D152220
2023-05-10[lldb][NFCI] Remove n^2 loops and simplify iterator usageFelipe de Azevedo Piovezan
The code inside Broadcaster makes usage of iterators using olden C++ coding style. Hidden in this old style is a couple of N^2 loops: we iterate over a map (sequentially), removing the first element that matches some predicate. The search is _always_ done from the start of the map, which implies that, if the map has N elements and if all matches happen on the second half of the map, then we visit the first N/2 elements exactly N/2 * N/2 times. Ideally some of the code here would benefit from `std::map`s own "erase_if", but this is only available with C++20: https://en.cppreference.com/w/cpp/container/map/erase_if We spent quite some time trying to make these loops more elegant, but it is surprisingly tricky to do so. Differential Revision: https://reviews.llvm.org/D150219
2023-05-09[lldb] Simplify predicates of find_if in BroadcastManagerAlex Langford
We had some custom classes that were used as the predicate for `std::find_if`. It would be a lot simpler if we used lambdas instead. Differential Revision: https://reviews.llvm.org/D150168
2023-04-25[lldb/Utility] Add opt-in shadow mode to event listenersMed Ismail Bennani
This patch augments lldb's event listeners with a new shadow mode. As the name suggests, this mode allows events to be copied to an additional listener to perform event monitoring, without interferring with the event life cycle. One of our use case for this, is to be able to listen to public process events while making sure the events will still be delivered to the default process listener (the debugger listener in most cases). Differential Revision: https://reviews.llvm.org/D148397 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-03-03Fix up the "lldb log break" channel output.Jim Ingham
1) Make the BreakpointEventData::Dump actually do something useful. 2) Make the Breakpoint events print when the break log channel is on without having to turn on the events channel. Differential Revision: https://reviews.llvm.org/D120917
2022-02-03[lldb] Rename Logging.h to LLDBLog.h and clean up includesPavel Labath
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 Labath
2021-05-26[lldb][NFC] Use C++ versions of the deprecated C standard library headersRaphael Isemann
The C headers are deprecated so as requested in D102845, this is replacing them all with their (not deprecated) C++ equivalent. Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D103084
2020-03-02[lldb/Utility] Use emplace_back instead of push_back (NFC)Jonas Devlieghere
Use emplace_back to allow for in-place construction of the BroadcastEventSpec instead of copying it.
2020-02-11[lldb][NFC] Remove several inefficient ConstString -> const char * -> ↵Raphael Isemann
StringRef conversions StringRef will call strlen on the C string which is inefficient (as ConstString already knows the string lenght and so does StringRef). This patch replaces all those calls with GetStringRef() which doesn't recompute the length.
2020-02-04Fix BroadcasterManager::RemoveListener to really remove the listenerReid Kleckner
This appears to be a real bug caught by -Wunused-value. std::find_if doesn't modify the underlying collection, it just returns an iterator pointing to the matching element. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D74010
2020-01-24[lldb][NFC] Fix all formatting errors in .cpp file headersRaphael Isemann
Summary: A *.cpp file header in LLDB (and in LLDB) should like this: ``` //===-- TestUtilities.cpp -------------------------------------------------===// ``` However in LLDB most of our source files have arbitrary changes to this format and these changes are spreading through LLDB as folks usually just use the existing source files as templates for their new files (most notably the unnecessary editor language indicator `-*- C++ -*-` is spreading and in every review someone is pointing out that this is wrong, resulting in people pointing out that this is done in the same way in other files). This patch removes most of these inconsistencies including the editor language indicators, all the different missing/additional '-' characters, files that center the file name, missing trailing `===//` (mostly caused by clang-format breaking the line). Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere Reviewed By: JDevlieghere Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D73258
2019-12-13[lldb][NFC] Remove unused includes in Utility's source filesRaphael Isemann
2019-11-11lldb: Fix some -Wdeprecated-copy warningsPavel Labath
gcc-9 started warning when a class defined a copy constructor without a copy assignment operator (or vice-versa). This fixes those warnings by deleting the other special member too (after verifying it doesn't do anything non-trivial).
2019-07-24[Logging] Replace Log::Printf with LLDB_LOG macro (NFC)Jonas Devlieghere
This patch replaces explicit calls to log::Printf with the new LLDB_LOGF macro. The macro is similar to LLDB_LOG but supports printf-style format strings, instead of formatv-style format strings. So instead of writing: if (log) log->Printf("%s\n", str); You'd write: LLDB_LOG(log, "%s\n", str); This change was done mechanically with the command below. I replaced the spurious if-checks with vim, since I know how to do multi-line replacements with it. find . -type f -name '*.cpp' -exec \ sed -i '' -E 's/log->Printf\(/LLDB_LOGF\(log, /g' "{}" + Differential revision: https://reviews.llvm.org/D65128 llvm-svn: 366936
2019-05-24[Utility] Small improvements to the Broadcaster class (NFC)Jonas Devlieghere
I touched the Broadcaster class earlier today (r361544) and noticed a few things that could be improved. This patch includes variety of small fixes: use early returns, use LLDB_LOG macro, use doxygen comments and finally format the class. llvm-svn: 361597
2019-05-23[Utility] Avoid a few unnecessary copies (NFC)Jonas Devlieghere
Avoid unnecessary copies by either passing by const-reference or moving the argument. llvm-svn: 361544
2019-05-15Delete unnecessary copy ctors/copy assignment operatorsFangrui Song
It's the simplest and gives the cleanest semantics. llvm-svn: 360762
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-12-14Move Broadcaster+Listener+Event combo from Core into UtilityPavel Labath
Summary: These are general purpose "utility" classes, whose functionality is not debugger-specific in any way. As such, I believe they belong in the Utility module. This doesn't break any particular dependency (yet), but it reduces the number of Core dependencies across the board. Reviewers: zturner, jingham, teemperor, clayborg Subscribers: mgorny, lldb-commits Differential Revision: https://reviews.llvm.org/D55361 llvm-svn: 349157