[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)
David Spickett via lldb-commits
lldb-commits at lists.llvm.org
Mon Oct 23 07:38:38 PDT 2023
================
@@ -1506,13 +1513,39 @@ static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
ExecutionContextScope *exe_scope =
interpreter.GetExecutionContext().GetBestExecutionContextScope();
- DumpAddress(exe_scope, so_addr, verbose, all_ranges, strm);
+ DumpAddress(exe_scope, so_addr, verbose, all_ranges, strm, nullptr);
return true;
}
return false;
}
+//===========================================================================================
+
+// This function is the one which colorizes the regex symbol searched
+static void PrintRed(Stream &strm, const char *text, const char *name) {
+ const std::string red_start = ANSI_ESC_START + std::to_string(ANSI_FG_COLOR_RED) + ANSI_ESC_END;
+ const std::string reset_color = ANSI_ESC_START + std::to_string(ANSI_CTRL_NORMAL) + ANSI_ESC_END;
+
+ const char *match = text;
+ size_t name_len = strlen(name);
----------------
DavidSpickett wrote:
https://en.cppreference.com/w/c/string/byte/strlen
Specifically:
```
The behavior is undefined if str is not a pointer to a null-terminated byte string.
```
I won't go into what that means according to the standard but here specifically, if clang knew a call to PrintRed took a nullptr always, it could make essentially choose the result of strlen to be almost anything. Which is not what we want.
So, as you suggested in your comment on the PR page, starting with some `if a nullptr then just print it out normally` is a good idea.
https://github.com/llvm/llvm-project/pull/69422
More information about the lldb-commits
mailing list