aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMehdi Amini <joker.eph@gmail.com>2025-07-26 11:34:10 +0200
committerGitHub <noreply@github.com>2025-07-26 11:34:10 +0200
commit5d26e3c227f4b4a1761a8b0001b3165198def479 (patch)
treedbc958b381a7a05a54481fa079f12e81d5fe2422
parent5ec6ac882c9fffaae6cf194f738e86f796394cd3 (diff)
downloadllvm-5d26e3c227f4b4a1761a8b0001b3165198def479.zip
llvm-5d26e3c227f4b4a1761a8b0001b3165198def479.tar.gz
llvm-5d26e3c227f4b4a1761a8b0001b3165198def479.tar.bz2
Strip the full path from __FILE__ in the LDBG macro and keep only the filename (#150677)
-rw-r--r--llvm/cmake/modules/LLVMProcessSources.cmake9
-rw-r--r--llvm/include/llvm/Support/DebugLog.h20
2 files changed, 29 insertions, 0 deletions
diff --git a/llvm/cmake/modules/LLVMProcessSources.cmake b/llvm/cmake/modules/LLVMProcessSources.cmake
index 0670d60..a7f9517 100644
--- a/llvm/cmake/modules/LLVMProcessSources.cmake
+++ b/llvm/cmake/modules/LLVMProcessSources.cmake
@@ -58,6 +58,15 @@ function(llvm_process_sources OUT_VAR)
set(sources ${ARG_UNPARSED_ARGUMENTS})
llvm_check_source_file_list(${sources})
+ foreach(fn ${sources})
+ get_filename_component(suf ${fn} EXT)
+ if("${suf}" STREQUAL ".cpp" OR "${suf}" STREQUAL ".c")
+ get_filename_component(short_name ${fn} NAME)
+ set_source_files_properties(${fn} PROPERTIES COMPILE_DEFINITIONS "__SHORT_FILE__=\"${short_name}\"")
+ endif()
+ endforeach()
+
+
# This adds .td and .h files to the Visual Studio solution:
add_td_sources(sources)
find_all_header_files(hdrs "${ARG_ADDITIONAL_HEADER_DIRS}")
diff --git a/llvm/include/llvm/Support/DebugLog.h b/llvm/include/llvm/Support/DebugLog.h
index 3e53944..b1b17e3 100644
--- a/llvm/include/llvm/Support/DebugLog.h
+++ b/llvm/include/llvm/Support/DebugLog.h
@@ -26,10 +26,17 @@ namespace llvm {
// << "] " << "Bitset contains: " << Bitset << "\n");
#define LDBG() DEBUGLOG_WITH_STREAM_AND_TYPE(llvm::dbgs(), DEBUG_TYPE)
+#if defined(__SHORT_FILE__)
+#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, TYPE) \
+ for (bool _c = (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)); _c; \
+ _c = false) \
+ ::llvm::impl::LogWithNewline(TYPE, __SHORT_FILE__, __LINE__, (STREAM))
+#else
#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, TYPE) \
for (bool _c = (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)); _c; \
_c = false) \
::llvm::impl::LogWithNewline(TYPE, __FILE__, __LINE__, (STREAM))
+#endif
namespace impl {
class LogWithNewline {
@@ -37,6 +44,9 @@ public:
LogWithNewline(const char *debug_type, const char *file, int line,
raw_ostream &os)
: os(os) {
+#if !defined(__SHORT_FILE__)
+ file = ::llvm::impl::LogWithNewline::getShortFileName(file);
+#endif
if (debug_type)
os << "[" << debug_type << "] ";
os << file << ":" << line << " ";
@@ -51,6 +61,16 @@ public:
LogWithNewline(const LogWithNewline &) = delete;
LogWithNewline &operator=(const LogWithNewline &) = delete;
LogWithNewline &operator=(LogWithNewline &&) = delete;
+ static constexpr const char *getShortFileName(const char *path) {
+ // Remove the path prefix from the file name.
+ const char *filename = path;
+ for (const char *p = path; *p != '\0'; ++p) {
+ if (*p == '/' || *p == '\\') {
+ filename = p + 1;
+ }
+ }
+ return filename;
+ }
private:
raw_ostream &os;