[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:41:32 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/strstr

```
The behavior is undefined if either str or substr is not a pointer to a null-terminated byte string.
```

You see the theme, a lot of these functions do not check for you.

It may be helpful that a pointer to the empty string `""` will not be nullptr, a nullptr literally cannot point to anything, it's an invalid pointer (sort of, see the standards if you want the super specific language).

The point being that when you're coming from a language without strings that can be null and can only be empty string or some characters, that difference can be confusing.

https://github.com/llvm/llvm-project/pull/69422


More information about the lldb-commits mailing list