[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel created https://github.com/llvm/llvm-project/pull/72040 libunwind already puts logging facilities behind macros so that they can be turned on and off. The one place where this isn't done yet is for debug output tracing DWARF evaluation. The code there directly calls `fprintf`. This becomes a problem when one wants to build libunwind for a baremetal target where `fprintf` isn't available. This change introduces a set of `_LIBUNWIND_TRACE_DWARF_EVAL` macros in the style of the already existing macros to remove the direct dependency on `fprintf`. >From 85eb8a3f5accfdb8c90b8e45a7ff0f7480e648ce Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sat, 11 Nov 2023 22:09:05 +0100 Subject: [PATCH] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL --- libunwind/src/DwarfInstructions.hpp | 161 ++-- libunwind/src/config.h | 15 +++ 2 files changed, 70 insertions(+), 106 deletions(-) diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index 9962c2ffa0ca34f..015489bab1d3ac1 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL +for (pint_t *t = sp; t > stack; --t) { + _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); } +#endif uint8_t opcode = addressSpace.get8(p++); sint_t svalue, svalue2; pint_t value; @@ -409,16 +407,14 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.getP(p); p += sizeof(pint_t); *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_deref: // pop stack, dereference, push result value = *sp--; *(++sp) = addressSpace.getP(value); - if (log) -fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const1u: @@ -426,8 +422,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get8(p); p += 1; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const1s: @@ -435,8 +430,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, svalue = (int8_t) addressSpace.get8(p); p += 1; *(++sp) = (pint_t)svalue; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)svalue); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)svalue); break; case DW_OP_const2u: @@ -444,8 +438,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get16(p); p += 2; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const2s: @@ -453,8 +446,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, svalue = (int16_t) addressSpace.get16(p); p += 2; *(++sp) = (pint_t)svalue; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)svalue); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)svalue); break; case DW_OP_const4u: @@ -462,8 +454,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get32(p); p += 4; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW
[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
@@ -223,6 +223,21 @@ } while (0) #endif +#define _LIBUNWIND_TRACING_DWARF_EVAL (0) michael-kenzel wrote: Yeah, I figured if anyone ever actually needed to turn this on for debug builds in general, they'd have added that option. It seemed to me like this is more just some convenience thing for whoever was working on that code. I didn't want to couple this to `NDEBUG` or some external function like the other stuff does since this output so far wasn't turned on that way either. And adding a whole CMake build option just for this seemed like overkill. Given the way it's been used so far, doing it via a CMake option would likely get in the way more than anything else since that would force a wider rebuild every time you switch. So I just kept the overall behavior as-is. With the macro in the config header now, it will be trivial to add a build flag or something, should the need ever arise. https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
@@ -223,6 +223,21 @@ } while (0) #endif +#define _LIBUNWIND_TRACING_DWARF_EVAL (0) michael-kenzel wrote: In fact, since this is more some kind of internal feature, maybe it shouldn't be in the config header at all but rather just defined and undef'ed again inside the original function? Though having all the stuff to do with logging defined in a similar fashion in one place is probably preferable… https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [clang] [llvm] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel updated https://github.com/llvm/llvm-project/pull/72040 >From 85eb8a3f5accfdb8c90b8e45a7ff0f7480e648ce Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sat, 11 Nov 2023 22:09:05 +0100 Subject: [PATCH] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL --- libunwind/src/DwarfInstructions.hpp | 161 ++-- libunwind/src/config.h | 15 +++ 2 files changed, 70 insertions(+), 106 deletions(-) diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index 9962c2ffa0ca34f..015489bab1d3ac1 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL +for (pint_t *t = sp; t > stack; --t) { + _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); } +#endif uint8_t opcode = addressSpace.get8(p++); sint_t svalue, svalue2; pint_t value; @@ -409,16 +407,14 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.getP(p); p += sizeof(pint_t); *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_deref: // pop stack, dereference, push result value = *sp--; *(++sp) = addressSpace.getP(value); - if (log) -fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const1u: @@ -426,8 +422,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get8(p); p += 1; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const1s: @@ -435,8 +430,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, svalue = (int8_t) addressSpace.get8(p); p += 1; *(++sp) = (pint_t)svalue; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)svalue); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)svalue); break; case DW_OP_const2u: @@ -444,8 +438,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get16(p); p += 2; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const2s: @@ -453,8 +446,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, svalue = (int16_t) addressSpace.get16(p); p += 2; *(++sp) = (pint_t)svalue; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)svalue); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)svalue); break; case DW_OP_const4u: @@ -462,8 +454,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get32(p); p += 4; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const4s: @@ -471,8 +462,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, svalue = (int32_t)addressSpace.get32(p); p += 4; *(++sp) = (pint_t)svalue; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)svalue); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)svalue); break; case DW_OP_const8u: @@ -480,8 +470,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace,
[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel updated https://github.com/llvm/llvm-project/pull/72040 >From cd42165f8b3c74f58632ee12d60aa5cfc6a14b4a Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sat, 11 Nov 2023 22:09:05 +0100 Subject: [PATCH] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL --- libunwind/src/DwarfInstructions.hpp | 169 +++- libunwind/src/config.h | 15 +++ 2 files changed, 78 insertions(+), 106 deletions(-) diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index 9962c2ffa0ca34f..ce59ca2ad73c3bd 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL +for (pint_t *t = sp; t > stack; --t) { + _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); } +#endif uint8_t opcode = addressSpace.get8(p++); sint_t svalue, svalue2; pint_t value; @@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.getP(p); p += sizeof(pint_t); *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_deref: // pop stack, dereference, push result value = *sp--; *(++sp) = addressSpace.getP(value); - if (log) -fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n", + (uint64_t)value); break; case DW_OP_const1u: @@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get8(p); p += 1; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const1s: @@ -435,8 +431,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, svalue = (int8_t) addressSpace.get8(p); p += 1; *(++sp) = (pint_t)svalue; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)svalue); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)svalue); break; case DW_OP_const2u: @@ -444,8 +439,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get16(p); p += 2; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const2s: @@ -453,8 +447,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, svalue = (int16_t) addressSpace.get16(p); p += 2; *(++sp) = (pint_t)svalue; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)svalue); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)svalue); break; case DW_OP_const4u: @@ -462,8 +455,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get32(p); p += 4; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const4s: @@ -471,8 +463,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, svalue = (int32_t)addressSpace.get32(p); p += 4; *(++sp) = (pint_t)svalue; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)svalue); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)svalue); break; case DW_OP_const8u: @@ -480,8 +471,7 @@ DwarfInstructions::e
[libunwind] [libunwind] remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel created https://github.com/llvm/llvm-project/pull/72043 libunwind uses a minimum set of necessary standard library functions, basically just `memset` and `memcpy`. There is a single use of `strcpy` to copy the bytes `"CLNGUNW"` into a `uint64_t` object. This is both an arguably odd use of the `strcpy` function as well as it unnecessarily widens the set of library functions that must be available to build libunwind, which can be an obstacle in baremetal scenarios. This change simply replaces this one `strcpy` with the more fundamental `memcpy`. >From 63b201389da0e3efce2636cda47b9680869b512e Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sun, 12 Nov 2023 02:46:15 +0100 Subject: [PATCH] [libunwind] remove unnecessary strcpy dependency --- libunwind/src/UnwindLevel1-gcc-ext.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libunwind/src/UnwindLevel1-gcc-ext.c b/libunwind/src/UnwindLevel1-gcc-ext.c index d343f4e6e9cc837..32c872ffade1fd0 100644 --- a/libunwind/src/UnwindLevel1-gcc-ext.c +++ b/libunwind/src/UnwindLevel1-gcc-ext.c @@ -143,7 +143,7 @@ _Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) { // Create a mock exception object for force unwinding. _Unwind_Exception ex; memset(&ex, '\0', sizeof(ex)); - strcpy((char *)&ex.exception_class, "CLNGUNW"); + memcpy(&ex.exception_class, "CLNGUNW", sizeof(ex.exception_class)); #endif // walk each frame ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel updated https://github.com/llvm/llvm-project/pull/72040 >From 00742101facde57594384727de3359d1d85554a4 Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sat, 11 Nov 2023 22:09:05 +0100 Subject: [PATCH] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL --- libunwind/src/DwarfInstructions.hpp | 171 ++-- libunwind/src/config.h | 15 +++ 2 files changed, 78 insertions(+), 108 deletions(-) diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index 9962c2ffa0ca34f..82ea9b8a0f82a56 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL +for (pint_t *t = sp; t > stack; --t) { + _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); } +#endif uint8_t opcode = addressSpace.get8(p++); sint_t svalue, svalue2; pint_t value; @@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.getP(p); p += sizeof(pint_t); *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_deref: // pop stack, dereference, push result value = *sp--; *(++sp) = addressSpace.getP(value); - if (log) -fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n", + (uint64_t)value); break; case DW_OP_const1u: @@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get8(p); p += 1; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const1s: @@ -435,8 +431,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, svalue = (int8_t) addressSpace.get8(p); p += 1; *(++sp) = (pint_t)svalue; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)svalue); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)svalue); break; case DW_OP_const2u: @@ -444,8 +439,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get16(p); p += 2; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const2s: @@ -453,8 +447,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, svalue = (int16_t) addressSpace.get16(p); p += 2; *(++sp) = (pint_t)svalue; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)svalue); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)svalue); break; case DW_OP_const4u: @@ -462,8 +455,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get32(p); p += 4; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const4s: @@ -471,8 +463,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, svalue = (int32_t)addressSpace.get32(p); p += 4; *(++sp) = (pint_t)svalue; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)svalue); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)svalue); break; case DW_OP_const8u: @@ -480,8 +471,7 @@ DwarfInstructions::e
[libunwind] [libunwind] remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel updated https://github.com/llvm/llvm-project/pull/72043 >From c423c5bd51bd7aa093025b2892706b1968eba09d Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sun, 12 Nov 2023 02:46:15 +0100 Subject: [PATCH] [libunwind] Remove unnecessary strcpy dependency --- libunwind/src/UnwindLevel1-gcc-ext.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libunwind/src/UnwindLevel1-gcc-ext.c b/libunwind/src/UnwindLevel1-gcc-ext.c index d343f4e6e9cc837..32c872ffade1fd0 100644 --- a/libunwind/src/UnwindLevel1-gcc-ext.c +++ b/libunwind/src/UnwindLevel1-gcc-ext.c @@ -143,7 +143,7 @@ _Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) { // Create a mock exception object for force unwinding. _Unwind_Exception ex; memset(&ex, '\0', sizeof(ex)); - strcpy((char *)&ex.exception_class, "CLNGUNW"); + memcpy(&ex.exception_class, "CLNGUNW", sizeof(ex.exception_class)); #endif // walk each frame ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel updated https://github.com/llvm/llvm-project/pull/72040 >From 7e285a5121be99e41097e4615cab7568e1f4b7d0 Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sat, 11 Nov 2023 22:09:05 +0100 Subject: [PATCH] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL --- libunwind/src/DwarfInstructions.hpp | 171 ++-- libunwind/src/config.h | 15 +++ 2 files changed, 78 insertions(+), 108 deletions(-) diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index 9962c2ffa0ca34f..82ea9b8a0f82a56 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL +for (pint_t *t = sp; t > stack; --t) { + _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); } +#endif uint8_t opcode = addressSpace.get8(p++); sint_t svalue, svalue2; pint_t value; @@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.getP(p); p += sizeof(pint_t); *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_deref: // pop stack, dereference, push result value = *sp--; *(++sp) = addressSpace.getP(value); - if (log) -fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n", + (uint64_t)value); break; case DW_OP_const1u: @@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get8(p); p += 1; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const1s: @@ -435,8 +431,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, svalue = (int8_t) addressSpace.get8(p); p += 1; *(++sp) = (pint_t)svalue; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)svalue); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)svalue); break; case DW_OP_const2u: @@ -444,8 +439,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get16(p); p += 2; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const2s: @@ -453,8 +447,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, svalue = (int16_t) addressSpace.get16(p); p += 2; *(++sp) = (pint_t)svalue; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)svalue); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)svalue); break; case DW_OP_const4u: @@ -462,8 +455,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get32(p); p += 4; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const4s: @@ -471,8 +463,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, svalue = (int32_t)addressSpace.get32(p); p += 4; *(++sp) = (pint_t)svalue; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)svalue); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)svalue); break; case DW_OP_const8u: @@ -480,8 +471,7 @@ DwarfInstructions::e
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
michael-kenzel wrote: > I would assume this is already transformed to memcpy but I guess it won't be > for -O0 [I did some testing on this](https://godbolt.org/z/YMEjbxYd9): it seems that gcc replaces the `strcpy` with a simple `mov` even under `-O0`, but not the `memcpy`. clang does the reverse: it replaces the `memcpy` with a `mov` even under `-O0` but not the `strcpy`. So it's a bit of a wash (I didn't expect either compiler to transform any of these with `-O0` tbqh). Though since libunwind is primarily meant to be used with LLVM, this change arguably presents the tiniest codegen improvement. On either compiler, turning on optimizations (even just to `-O1`) results in the exact same codegen from either version (as one would expect). https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
@@ -143,7 +143,7 @@ _Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) { // Create a mock exception object for force unwinding. _Unwind_Exception ex; memset(&ex, '\0', sizeof(ex)); - strcpy((char *)&ex.exception_class, "CLNGUNW"); + memcpy(&ex.exception_class, "CLNGUNW", sizeof(ex.exception_class)); michael-kenzel wrote: My reasoning was that if the string happened to be too long for some reason, we'd want to ensure that we don't write past the member. Either option, using the string length or member length, has the downside of not considering the other length. Ideally, the string would be some constant and we'd have a `_Static_assert` to ensure the sizes match. But I couldn't find a simple way to put this into plain C without making this code significantly more complex. I was also not quite sure what's the range of versions of C this is supposed to build under, which would have implications regarding whether `_Static_assert` can be used at all or is deprecated in favor of `static_assert`… One very simple solution (at least code-wise) would be to just do ```c _Unwind_Exception ex = { .exception_class = 0x574E55474E4C43 // "CLNGUNW" }; ``` But this then assumes little endian and so would be a potential ABI break? Overall, I think it's reasonable to assume that this string isn't just gonna change in a way that would make it not match the size of the member anymore. The current implementation was already broken in that case as well. Unfortunately, no compiler seems to issue a warning if you make the string not match the size of the member. https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel updated https://github.com/llvm/llvm-project/pull/72043 >From d5adc242a9c52c7de2a860489a4292b7461b6164 Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sun, 12 Nov 2023 02:46:15 +0100 Subject: [PATCH] [libunwind] Remove unnecessary strcpy dependency --- libunwind/src/UnwindLevel1-gcc-ext.c | 2 +- libunwind/test/forceunwind.pass.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libunwind/src/UnwindLevel1-gcc-ext.c b/libunwind/src/UnwindLevel1-gcc-ext.c index d343f4e6e9cc837..32c872ffade1fd0 100644 --- a/libunwind/src/UnwindLevel1-gcc-ext.c +++ b/libunwind/src/UnwindLevel1-gcc-ext.c @@ -143,7 +143,7 @@ _Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) { // Create a mock exception object for force unwinding. _Unwind_Exception ex; memset(&ex, '\0', sizeof(ex)); - strcpy((char *)&ex.exception_class, "CLNGUNW"); + memcpy(&ex.exception_class, "CLNGUNW", sizeof(ex.exception_class)); #endif // walk each frame diff --git a/libunwind/test/forceunwind.pass.cpp b/libunwind/test/forceunwind.pass.cpp index 8c26551b6d0b678..db499d8bc30894e 100644 --- a/libunwind/test/forceunwind.pass.cpp +++ b/libunwind/test/forceunwind.pass.cpp @@ -61,7 +61,7 @@ __attribute__((noinline)) void foo() { #if defined(_LIBUNWIND_ARM_EHABI) // Create a mock exception object. memset(e, '\0', sizeof(*e)); - strcpy(reinterpret_cast(&e->exception_class), "CLNGUNW"); + memcpy(&e->exception_class, "CLNGUNW", sizeof(e->exception_class)); #endif _Unwind_ForcedUnwind(e, stop, (void *)&foo); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
michael-kenzel wrote: I found another use of the same string copying in `tests/forceunwind.pass.cpp` and updated that to match. https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
@@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL michael-kenzel wrote: good question. I think it might be a good idea to completely remove `#include ` everywhere unless some logging is active. I can try to add that. Though maybe this should be a separate PR since I think if we do this, we should do this in the library as a whole? It seems to be included in a majority of the files. Though all those includes are kinda redundant since they all include `"config.h"` anyways, which already includes ``. I guess we could just conditionally include `` in `"config.h"` only when logging is active and remove the include everywhere else? https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
@@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL michael-kenzel wrote: Actually, there seems to be more of the same: https://github.com/llvm/llvm-project/blob/d97981c98a70ebeaa8901f34921b0a69a068ff5d/libunwind/src/UnwindCursor.hpp#L1714 I just overlooked that since that path wasn't being built in my setup. I'll update this patch to do the same thing for this code too and remove the `` includes. https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel converted_to_draft https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
@@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL michael-kenzel wrote: makes sense, I'll just leave the test as-is. https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel updated https://github.com/llvm/llvm-project/pull/72040 >From ef0ec53cdcc3cd2b42bfaafe2504f4e90fbf0c2e Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sat, 11 Nov 2023 22:09:05 +0100 Subject: [PATCH] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL --- libunwind/src/AddressSpace.hpp| 5 +- libunwind/src/DwarfInstructions.hpp | 173 +++--- libunwind/src/DwarfParser.hpp | 2 +- libunwind/src/Unwind-EHABI.cpp| 2 +- libunwind/src/UnwindCursor.hpp| 77 libunwind/src/UnwindLevel1-gcc-ext.c | 1 - libunwind/src/UnwindLevel1.c | 1 - libunwind/src/config.h| 33 +++- libunwind/test/aix_signal_unwind.pass.sh.S| 2 +- libunwind/test/bad_unwind_info.pass.cpp | 1 - libunwind/test/forceunwind.pass.cpp | 3 - libunwind/test/frameheadercache_test.pass.cpp | 2 +- libunwind/test/signal_unwind.pass.cpp | 2 - libunwind/test/unwind_leaffunction.pass.cpp | 2 - 14 files changed, 136 insertions(+), 170 deletions(-) diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index 5551c7d4bef1c56..7044c492e7adb6c 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -13,7 +13,6 @@ #define __ADDRESSSPACE_HPP__ #include -#include #include #include @@ -672,7 +671,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, Dl_info dyldInfo; if (dladdr((void *)addr, &dyldInfo)) { if (dyldInfo.dli_sname != NULL) { - snprintf(buf, bufLen, "%s", dyldInfo.dli_sname); + strncpy(buf, dyldInfo.dli_sname, bufLen); *offset = (addr - (pint_t) dyldInfo.dli_saddr); return true; } @@ -681,7 +680,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, uint16_t nameLen; char *funcName = getFuncNameFromTBTable(addr, nameLen, offset); if (funcName != NULL) { -snprintf(buf, bufLen, "%.*s", nameLen, funcName); +strncpy(buf, funcName, nameLen < bufLen ? nameLen : bufLen); return true; } #else diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index bd9ece60ee5881a..9a46833e6726081 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -12,8 +12,8 @@ #ifndef __DWARF_INSTRUCTIONS_HPP__ #define __DWARF_INSTRUCTIONS_HPP__ +#include #include -#include #include #include "DwarfParser.hpp" @@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL +for (pint_t *t = sp; t > stack; --t) { + _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); } +#endif uint8_t opcode = addressSpace.get8(p++); sint_t svalue, svalue2; pint_t value; @@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.getP(p); p += sizeof(pint_t); *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_deref: // pop stack, dereference, push result value = *sp--; *(++sp) = addressSpace.getP(value); - if (log) -fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n", + (uint64_t)value); break; case DW_OP_const1u: @@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get8(p); p += 1; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const1s: @@ -435,8 +431,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &ad
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel updated https://github.com/llvm/llvm-project/pull/72040 >From 42bfd80e85095d8a1c94926fb907874f1c73f5c3 Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sat, 11 Nov 2023 22:09:05 +0100 Subject: [PATCH] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL --- libunwind/src/AddressSpace.hpp| 5 +- libunwind/src/DwarfInstructions.hpp | 173 +++--- libunwind/src/DwarfParser.hpp | 2 +- libunwind/src/Unwind-EHABI.cpp| 2 +- libunwind/src/UnwindCursor.hpp| 77 libunwind/src/UnwindLevel1-gcc-ext.c | 1 - libunwind/src/UnwindLevel1.c | 1 - libunwind/src/config.h| 33 +++- libunwind/test/aix_signal_unwind.pass.sh.S| 2 +- libunwind/test/bad_unwind_info.pass.cpp | 1 - libunwind/test/forceunwind.pass.cpp | 3 - libunwind/test/frameheadercache_test.pass.cpp | 2 +- libunwind/test/signal_unwind.pass.cpp | 2 - libunwind/test/unwind_leaffunction.pass.cpp | 2 - 14 files changed, 136 insertions(+), 170 deletions(-) diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index 5551c7d4bef1c56..7044c492e7adb6c 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -13,7 +13,6 @@ #define __ADDRESSSPACE_HPP__ #include -#include #include #include @@ -672,7 +671,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, Dl_info dyldInfo; if (dladdr((void *)addr, &dyldInfo)) { if (dyldInfo.dli_sname != NULL) { - snprintf(buf, bufLen, "%s", dyldInfo.dli_sname); + strncpy(buf, dyldInfo.dli_sname, bufLen); *offset = (addr - (pint_t) dyldInfo.dli_saddr); return true; } @@ -681,7 +680,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, uint16_t nameLen; char *funcName = getFuncNameFromTBTable(addr, nameLen, offset); if (funcName != NULL) { -snprintf(buf, bufLen, "%.*s", nameLen, funcName); +strncpy(buf, funcName, nameLen < bufLen ? nameLen : bufLen); return true; } #else diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index bd9ece60ee5881a..9a46833e6726081 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -12,8 +12,8 @@ #ifndef __DWARF_INSTRUCTIONS_HPP__ #define __DWARF_INSTRUCTIONS_HPP__ +#include #include -#include #include #include "DwarfParser.hpp" @@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL +for (pint_t *t = sp; t > stack; --t) { + _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); } +#endif uint8_t opcode = addressSpace.get8(p++); sint_t svalue, svalue2; pint_t value; @@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.getP(p); p += sizeof(pint_t); *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_deref: // pop stack, dereference, push result value = *sp--; *(++sp) = addressSpace.getP(value); - if (log) -fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n", + (uint64_t)value); break; case DW_OP_const1u: @@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get8(p); p += 1; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const1s: @@ -435,8 +431,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &ad
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel updated https://github.com/llvm/llvm-project/pull/72040 >From c78b3f5267a5809f1d29a17dd392a8a2d0b4147c Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sat, 11 Nov 2023 22:09:05 +0100 Subject: [PATCH] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL --- libunwind/src/AddressSpace.hpp| 5 +- libunwind/src/DwarfInstructions.hpp | 173 +++--- libunwind/src/DwarfParser.hpp | 2 +- libunwind/src/Unwind-EHABI.cpp| 2 +- libunwind/src/UnwindCursor.hpp| 77 libunwind/src/UnwindLevel1-gcc-ext.c | 1 - libunwind/src/UnwindLevel1.c | 1 - libunwind/src/config.h| 31 +++- libunwind/test/aix_signal_unwind.pass.sh.S| 2 +- libunwind/test/bad_unwind_info.pass.cpp | 1 - libunwind/test/forceunwind.pass.cpp | 3 - libunwind/test/frameheadercache_test.pass.cpp | 2 +- libunwind/test/signal_unwind.pass.cpp | 2 - libunwind/test/unwind_leaffunction.pass.cpp | 2 - 14 files changed, 135 insertions(+), 169 deletions(-) diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index 5551c7d4bef1c56..7044c492e7adb6c 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -13,7 +13,6 @@ #define __ADDRESSSPACE_HPP__ #include -#include #include #include @@ -672,7 +671,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, Dl_info dyldInfo; if (dladdr((void *)addr, &dyldInfo)) { if (dyldInfo.dli_sname != NULL) { - snprintf(buf, bufLen, "%s", dyldInfo.dli_sname); + strncpy(buf, dyldInfo.dli_sname, bufLen); *offset = (addr - (pint_t) dyldInfo.dli_saddr); return true; } @@ -681,7 +680,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, uint16_t nameLen; char *funcName = getFuncNameFromTBTable(addr, nameLen, offset); if (funcName != NULL) { -snprintf(buf, bufLen, "%.*s", nameLen, funcName); +strncpy(buf, funcName, nameLen < bufLen ? nameLen : bufLen); return true; } #else diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index bd9ece60ee5881a..9a46833e6726081 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -12,8 +12,8 @@ #ifndef __DWARF_INSTRUCTIONS_HPP__ #define __DWARF_INSTRUCTIONS_HPP__ +#include #include -#include #include #include "DwarfParser.hpp" @@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL +for (pint_t *t = sp; t > stack; --t) { + _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); } +#endif uint8_t opcode = addressSpace.get8(p++); sint_t svalue, svalue2; pint_t value; @@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.getP(p); p += sizeof(pint_t); *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_deref: // pop stack, dereference, push result value = *sp--; *(++sp) = addressSpace.getP(value); - if (log) -fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n", + (uint64_t)value); break; case DW_OP_const1u: @@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get8(p); p += 1; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const1s: @@ -435,8 +431,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &ad
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel updated https://github.com/llvm/llvm-project/pull/72040 >From f98bbd27427a3cc03dbb933c2fccbab73b557cec Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sat, 11 Nov 2023 22:09:05 +0100 Subject: [PATCH] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL --- libunwind/src/AddressSpace.hpp| 5 +- libunwind/src/DwarfInstructions.hpp | 173 +++--- libunwind/src/DwarfParser.hpp | 2 +- libunwind/src/Unwind-EHABI.cpp| 2 +- libunwind/src/UnwindCursor.hpp| 79 libunwind/src/UnwindLevel1-gcc-ext.c | 1 - libunwind/src/UnwindLevel1.c | 3 +- libunwind/src/config.h| 31 +++- libunwind/test/aix_signal_unwind.pass.sh.S| 2 +- libunwind/test/bad_unwind_info.pass.cpp | 1 - libunwind/test/forceunwind.pass.cpp | 3 - libunwind/test/frameheadercache_test.pass.cpp | 2 +- libunwind/test/signal_unwind.pass.cpp | 2 - libunwind/test/unwind_leaffunction.pass.cpp | 2 - 14 files changed, 137 insertions(+), 171 deletions(-) diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index 5551c7d4bef1c56..7044c492e7adb6c 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -13,7 +13,6 @@ #define __ADDRESSSPACE_HPP__ #include -#include #include #include @@ -672,7 +671,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, Dl_info dyldInfo; if (dladdr((void *)addr, &dyldInfo)) { if (dyldInfo.dli_sname != NULL) { - snprintf(buf, bufLen, "%s", dyldInfo.dli_sname); + strncpy(buf, dyldInfo.dli_sname, bufLen); *offset = (addr - (pint_t) dyldInfo.dli_saddr); return true; } @@ -681,7 +680,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, uint16_t nameLen; char *funcName = getFuncNameFromTBTable(addr, nameLen, offset); if (funcName != NULL) { -snprintf(buf, bufLen, "%.*s", nameLen, funcName); +strncpy(buf, funcName, nameLen < bufLen ? nameLen : bufLen); return true; } #else diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index bd9ece60ee5881a..9a46833e6726081 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -12,8 +12,8 @@ #ifndef __DWARF_INSTRUCTIONS_HPP__ #define __DWARF_INSTRUCTIONS_HPP__ +#include #include -#include #include #include "DwarfParser.hpp" @@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL +for (pint_t *t = sp; t > stack; --t) { + _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); } +#endif uint8_t opcode = addressSpace.get8(p++); sint_t svalue, svalue2; pint_t value; @@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.getP(p); p += sizeof(pint_t); *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_deref: // pop stack, dereference, push result value = *sp--; *(++sp) = addressSpace.getP(value); - if (log) -fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n", + (uint64_t)value); break; case DW_OP_const1u: @@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get8(p); p += 1; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const1s: @@ -435,8 +431,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &a
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel updated https://github.com/llvm/llvm-project/pull/72040 >From 0bedd8b680bf8f2957a6056e92eb1cb92a8666e3 Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sat, 11 Nov 2023 22:09:05 +0100 Subject: [PATCH] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL --- libunwind/src/AddressSpace.hpp| 5 +- libunwind/src/DwarfInstructions.hpp | 173 +++--- libunwind/src/DwarfParser.hpp | 2 +- libunwind/src/Unwind-EHABI.cpp| 2 +- libunwind/src/UnwindCursor.hpp| 79 libunwind/src/UnwindLevel1-gcc-ext.c | 1 - libunwind/src/UnwindLevel1.c | 3 +- libunwind/src/config.h| 31 +++- libunwind/test/aix_signal_unwind.pass.sh.S| 2 +- libunwind/test/bad_unwind_info.pass.cpp | 1 - libunwind/test/forceunwind.pass.cpp | 3 - libunwind/test/frameheadercache_test.pass.cpp | 2 +- libunwind/test/signal_unwind.pass.cpp | 2 - libunwind/test/unwind_leaffunction.pass.cpp | 2 - 14 files changed, 137 insertions(+), 171 deletions(-) diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index 5551c7d4bef1c56..7044c492e7adb6c 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -13,7 +13,6 @@ #define __ADDRESSSPACE_HPP__ #include -#include #include #include @@ -672,7 +671,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, Dl_info dyldInfo; if (dladdr((void *)addr, &dyldInfo)) { if (dyldInfo.dli_sname != NULL) { - snprintf(buf, bufLen, "%s", dyldInfo.dli_sname); + strncpy(buf, dyldInfo.dli_sname, bufLen); *offset = (addr - (pint_t) dyldInfo.dli_saddr); return true; } @@ -681,7 +680,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, uint16_t nameLen; char *funcName = getFuncNameFromTBTable(addr, nameLen, offset); if (funcName != NULL) { -snprintf(buf, bufLen, "%.*s", nameLen, funcName); +strncpy(buf, funcName, nameLen < bufLen ? nameLen : bufLen); return true; } #else diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index bd9ece60ee5881a..9a46833e6726081 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -12,8 +12,8 @@ #ifndef __DWARF_INSTRUCTIONS_HPP__ #define __DWARF_INSTRUCTIONS_HPP__ +#include #include -#include #include #include "DwarfParser.hpp" @@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL +for (pint_t *t = sp; t > stack; --t) { + _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); } +#endif uint8_t opcode = addressSpace.get8(p++); sint_t svalue, svalue2; pint_t value; @@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.getP(p); p += sizeof(pint_t); *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_deref: // pop stack, dereference, push result value = *sp--; *(++sp) = addressSpace.getP(value); - if (log) -fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n", + (uint64_t)value); break; case DW_OP_const1u: @@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get8(p); p += 1; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const1s: @@ -435,8 +431,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &a
[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel updated https://github.com/llvm/llvm-project/pull/72040 >From a72cef20e847e85a5fedb56d1b9d1414dbd7e516 Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sat, 11 Nov 2023 22:09:05 +0100 Subject: [PATCH] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL --- libunwind/src/AddressSpace.hpp| 5 +- libunwind/src/DwarfInstructions.hpp | 173 +++--- libunwind/src/DwarfParser.hpp | 2 +- libunwind/src/Unwind-EHABI.cpp| 2 +- libunwind/src/UnwindCursor.hpp| 79 libunwind/src/UnwindLevel1-gcc-ext.c | 1 - libunwind/src/UnwindLevel1.c | 3 +- libunwind/src/config.h| 37 +++- libunwind/test/aix_signal_unwind.pass.sh.S| 2 +- libunwind/test/bad_unwind_info.pass.cpp | 1 - libunwind/test/forceunwind.pass.cpp | 3 - libunwind/test/frameheadercache_test.pass.cpp | 2 +- libunwind/test/signal_unwind.pass.cpp | 2 - libunwind/test/unwind_leaffunction.pass.cpp | 2 - 14 files changed, 142 insertions(+), 172 deletions(-) diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index 5551c7d4bef1c56..7044c492e7adb6c 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -13,7 +13,6 @@ #define __ADDRESSSPACE_HPP__ #include -#include #include #include @@ -672,7 +671,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, Dl_info dyldInfo; if (dladdr((void *)addr, &dyldInfo)) { if (dyldInfo.dli_sname != NULL) { - snprintf(buf, bufLen, "%s", dyldInfo.dli_sname); + strncpy(buf, dyldInfo.dli_sname, bufLen); *offset = (addr - (pint_t) dyldInfo.dli_saddr); return true; } @@ -681,7 +680,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, uint16_t nameLen; char *funcName = getFuncNameFromTBTable(addr, nameLen, offset); if (funcName != NULL) { -snprintf(buf, bufLen, "%.*s", nameLen, funcName); +strncpy(buf, funcName, nameLen < bufLen ? nameLen : bufLen); return true; } #else diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index bd9ece60ee5881a..9a46833e6726081 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -12,8 +12,8 @@ #ifndef __DWARF_INSTRUCTIONS_HPP__ #define __DWARF_INSTRUCTIONS_HPP__ +#include #include -#include #include #include "DwarfParser.hpp" @@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL +for (pint_t *t = sp; t > stack; --t) { + _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); } +#endif uint8_t opcode = addressSpace.get8(p++); sint_t svalue, svalue2; pint_t value; @@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.getP(p); p += sizeof(pint_t); *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_deref: // pop stack, dereference, push result value = *sp--; *(++sp) = addressSpace.getP(value); - if (log) -fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n", + (uint64_t)value); break; case DW_OP_const1u: @@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get8(p); p += 1; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const1s: @@ -435,8 +431,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &a
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel updated https://github.com/llvm/llvm-project/pull/72040 >From f8b562dbd0c5927b92c5314ea70745b9b3ec1535 Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sat, 11 Nov 2023 22:09:05 +0100 Subject: [PATCH] [libunwind] Remove unnecessary dependencies on stdio.h for increased baremetal friendliness --- libunwind/src/AddressSpace.hpp| 5 +- libunwind/src/DwarfInstructions.hpp | 173 +++--- libunwind/src/DwarfParser.hpp | 2 +- libunwind/src/Unwind-EHABI.cpp| 2 +- libunwind/src/UnwindCursor.hpp| 79 libunwind/src/UnwindLevel1-gcc-ext.c | 1 - libunwind/src/UnwindLevel1.c | 3 +- libunwind/src/config.h| 37 +++- libunwind/test/aix_signal_unwind.pass.sh.S| 2 +- libunwind/test/bad_unwind_info.pass.cpp | 1 - libunwind/test/forceunwind.pass.cpp | 3 - libunwind/test/frameheadercache_test.pass.cpp | 2 +- libunwind/test/signal_unwind.pass.cpp | 2 - libunwind/test/unwind_leaffunction.pass.cpp | 2 - 14 files changed, 142 insertions(+), 172 deletions(-) diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index 5551c7d4bef1c56..7044c492e7adb6c 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -13,7 +13,6 @@ #define __ADDRESSSPACE_HPP__ #include -#include #include #include @@ -672,7 +671,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, Dl_info dyldInfo; if (dladdr((void *)addr, &dyldInfo)) { if (dyldInfo.dli_sname != NULL) { - snprintf(buf, bufLen, "%s", dyldInfo.dli_sname); + strncpy(buf, dyldInfo.dli_sname, bufLen); *offset = (addr - (pint_t) dyldInfo.dli_saddr); return true; } @@ -681,7 +680,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, uint16_t nameLen; char *funcName = getFuncNameFromTBTable(addr, nameLen, offset); if (funcName != NULL) { -snprintf(buf, bufLen, "%.*s", nameLen, funcName); +strncpy(buf, funcName, nameLen < bufLen ? nameLen : bufLen); return true; } #else diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index bd9ece60ee5881a..9a46833e6726081 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -12,8 +12,8 @@ #ifndef __DWARF_INSTRUCTIONS_HPP__ #define __DWARF_INSTRUCTIONS_HPP__ +#include #include -#include #include #include "DwarfParser.hpp" @@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL +for (pint_t *t = sp; t > stack; --t) { + _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); } +#endif uint8_t opcode = addressSpace.get8(p++); sint_t svalue, svalue2; pint_t value; @@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.getP(p); p += sizeof(pint_t); *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_deref: // pop stack, dereference, push result value = *sp--; *(++sp) = addressSpace.getP(value); - if (log) -fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n", + (uint64_t)value); break; case DW_OP_const1u: @@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get8(p); p += 1; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_const1s: @@ -435,8 +431,7 @@ DwarfInstructions::
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel closed https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
michael-kenzel wrote: As discussed, I've removed unnecessary includes of `` as well as a couple other unnecessary includes. I've put the include of `` in `config.h` under an `#ifdef` so it only gets included when logging is potentially active. I've also moved the include of `` from `config.h` into only the files that actually need it. In two places, I replaced the include `` with an include of the header that was actually needed (`` or ``). [AddressSpace.hpp](https://github.com/llvm/llvm-project/pull/72040/files#diff-dc10e493a84f7de241e331f66a5af195689f08d45a6fd0da90b275a662856327) was using `snprintf` to copy strings into a buffer. I replaced those uses with `strncpy` to remove the need for ``. Finally, I've added `_LIBUNWIND_TRACE_COMPACT_UNWIND` to also deal with the debug logging in [UnwindCursor.hpp](https://github.com/llvm/llvm-project/pull/72040/files#diff-e59aa90030d7262678863315066b19c20f770a3b02ef960961d7d01fa4b15596). Unfortunately, I can't really exercise all these code paths here as these changes now span code specific to multiple different platforms. I'll trust that if all the tests pass, that means it works… https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel reopened https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
michael-kenzel wrote: As discussed, I've removed unnecessary includes of `` as well as a couple other unnecessary includes. I've put the include of `` in `config.h` under an `#ifdef` so it only gets included when logging is potentially active. I've also moved the include of `` from `config.h` into only the files that actually need it. In two places, I replaced the include `` with an include of the header that was actually needed (`` or ``). [AddressSpace.hpp](https://github.com/llvm/llvm-project/pull/72040/files#diff-dc10e493a84f7de241e331f66a5af195689f08d45a6fd0da90b275a662856327) was using `snprintf` to copy strings into a buffer. I replaced those uses with `strncpy` to remove the need for ``. Finally, I've added `_LIBUNWIND_TRACE_COMPACT_UNWIND` to also deal with the debug logging in [UnwindCursor.hpp](https://github.com/llvm/llvm-project/pull/72040/files#diff-e59aa90030d7262678863315066b19c20f770a3b02ef960961d7d01fa4b15596). Unfortunately, I can't really exercise all these code paths here as these changes now span code specific to multiple different platforms. I'll trust that if all the tests pass, that means it works… https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel ready_for_review https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
@@ -672,7 +671,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, Dl_info dyldInfo; if (dladdr((void *)addr, &dyldInfo)) { if (dyldInfo.dli_sname != NULL) { - snprintf(buf, bufLen, "%s", dyldInfo.dli_sname); + strncpy(buf, dyldInfo.dli_sname, bufLen); michael-kenzel wrote: Indeed. I did a quick test on my machine here: ``` - Benchmark Time CPU Iterations - copy_snprintf 4005109 ns 4005097 ns 175 copy_strncpy 3580506 ns 3580409 ns 194 copy_memcpy_strlen3346781 ns 3346773 ns 213 ``` so doing `strlen` + `memcpy` seems to be the best option. I'll update the PR. https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel updated https://github.com/llvm/llvm-project/pull/72040 >From fcdccb35b8c641b99bfb72948520771d9969671a Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sat, 11 Nov 2023 22:09:05 +0100 Subject: [PATCH] [libunwind] Remove unnecessary dependencies on stdio.h for increased baremetal friendliness --- libunwind/src/AddressSpace.hpp| 10 +- libunwind/src/DwarfInstructions.hpp | 173 +++--- libunwind/src/DwarfParser.hpp | 2 +- libunwind/src/Unwind-EHABI.cpp| 2 +- libunwind/src/UnwindCursor.hpp| 79 libunwind/src/UnwindLevel1-gcc-ext.c | 1 - libunwind/src/UnwindLevel1.c | 3 +- libunwind/src/config.h| 37 +++- libunwind/test/aix_signal_unwind.pass.sh.S| 2 +- libunwind/test/bad_unwind_info.pass.cpp | 1 - libunwind/test/forceunwind.pass.cpp | 3 - libunwind/test/frameheadercache_test.pass.cpp | 2 +- libunwind/test/signal_unwind.pass.cpp | 2 - libunwind/test/unwind_leaffunction.pass.cpp | 2 - 14 files changed, 147 insertions(+), 172 deletions(-) diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index 5551c7d4bef1c56..3e4c06dc44520dc 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -13,7 +13,6 @@ #define __ADDRESSSPACE_HPP__ #include -#include #include #include @@ -672,7 +671,10 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, Dl_info dyldInfo; if (dladdr((void *)addr, &dyldInfo)) { if (dyldInfo.dli_sname != NULL) { - snprintf(buf, bufLen, "%s", dyldInfo.dli_sname); + size_t nameLen = strlen(dyldInfo.dli_sname); + size_t len = nameLen < (bufLen - 1) ? nameLen : (bufLen - 1); + memcpy(buf, dyldInfo.dli_sname, len); + buf[len] = '\0'; *offset = (addr - (pint_t) dyldInfo.dli_saddr); return true; } @@ -681,7 +683,9 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, uint16_t nameLen; char *funcName = getFuncNameFromTBTable(addr, nameLen, offset); if (funcName != NULL) { -snprintf(buf, bufLen, "%.*s", nameLen, funcName); +size_t len = nameLen < (bufLen - 1) ? nameLen : (bufLen - 1); +memcpy(buf, funcName, len); +buf[len] = '\0'; return true; } #else diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index bd9ece60ee5881a..9a46833e6726081 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -12,8 +12,8 @@ #ifndef __DWARF_INSTRUCTIONS_HPP__ #define __DWARF_INSTRUCTIONS_HPP__ +#include #include -#include #include #include "DwarfParser.hpp" @@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL +for (pint_t *t = sp; t > stack; --t) { + _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); } +#endif uint8_t opcode = addressSpace.get8(p++); sint_t svalue, svalue2; pint_t value; @@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.getP(p); p += sizeof(pint_t); *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_deref: // pop stack, dereference, push result value = *sp--; *(++sp) = addressSpace.getP(value); - if (log) -fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n", + (uint64_t)value); break; case DW_OP_const1u: @@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get8(p); p += 1; *(++sp) = value; - if (log) -fprintf(stderr, "
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
michael-kenzel wrote: > [AddressSpace.hpp](https://github.com/llvm/llvm-project/pull/72040/files#diff-dc10e493a84f7de241e331f66a5af195689f08d45a6fd0da90b275a662856327) > was using `snprintf` to copy strings into a buffer. I replaced those uses > with `strncpy` to remove the need for ``. As discussed with @arichardson, I've replaced `strncpy` with `strlen` + `memcpy`. https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
@@ -381,24 +381,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL michael-kenzel wrote: I would expect the compiler to optimize the loop away in an optimized build. If I remember correctly, and it's been a while, then the reason I did it this way was just to avoid generating a pointless loop also in an unoptimized build. https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
@@ -223,6 +221,41 @@ } while (0) #endif +#define _LIBUNWIND_TRACING_COMPACT_UNWIND (0) +#if !_LIBUNWIND_TRACING_COMPACT_UNWIND +#define _LIBUNWIND_TRACE_COMPACT_UNWIND0(msg) +#define _LIBUNWIND_TRACE_COMPACT_UNWIND(msg, ...) +#else +#define _LIBUNWIND_TRACE_COMPACT_UNWIND0(msg) \ + do { \ +fprintf(stderr, msg); \ + } while (0) +#define _LIBUNWIND_TRACE_COMPACT_UNWIND(msg, ...) \ + do { \ +fprintf(stderr, msg, __VA_ARGS__); \ + } while (0) michael-kenzel wrote: It probably would; the reason why I did it the way I did was consistency with the existing `_LIBUNWIND_LOG`/`_LIBUNWIND_LOG0` macros. I guess best would be to just rewrite those in your suggested way as well. But maybe this should be done in a separate PR to keep this one focused on just replacing `fprintf`? https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
@@ -223,6 +221,41 @@ } while (0) #endif +#define _LIBUNWIND_TRACING_COMPACT_UNWIND (0) +#if !_LIBUNWIND_TRACING_COMPACT_UNWIND +#define _LIBUNWIND_TRACE_COMPACT_UNWIND0(msg) +#define _LIBUNWIND_TRACE_COMPACT_UNWIND(msg, ...) +#else +#define _LIBUNWIND_TRACE_COMPACT_UNWIND0(msg) \ + do { \ +fprintf(stderr, msg); \ + } while (0) +#define _LIBUNWIND_TRACE_COMPACT_UNWIND(msg, ...) \ + do { \ +fprintf(stderr, msg, __VA_ARGS__); \ + } while (0) +#endif + +#define _LIBUNWIND_TRACING_DWARF_EVAL (0) +#if !_LIBUNWIND_TRACING_DWARF_EVAL +#define _LIBUNWIND_TRACE_DWARF_EVAL0(msg) +#define _LIBUNWIND_TRACE_DWARF_EVAL(msg, ...) +#else +#define _LIBUNWIND_TRACE_DWARF_EVAL0(msg) \ michael-kenzel wrote: same as above 🙂↕️ https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
michael-kenzel wrote: > @michael-kenzel Was there a reason why this never got merged? I don't think there was, I guess this just fell through the cracks… https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel edited https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel updated https://github.com/llvm/llvm-project/pull/72040 >From 70ef8570614f1fe8140f24bbe27f69f9c1deb994 Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sat, 11 Nov 2023 22:09:05 +0100 Subject: [PATCH] [libunwind] Remove unnecessary dependencies on stdio.h for increased baremetal friendliness --- libunwind/src/AddressSpace.hpp| 10 +- libunwind/src/DwarfInstructions.hpp | 173 +++--- libunwind/src/DwarfParser.hpp | 2 +- libunwind/src/Unwind-EHABI.cpp| 2 +- libunwind/src/UnwindCursor.hpp| 78 libunwind/src/UnwindLevel1-gcc-ext.c | 1 - libunwind/src/UnwindLevel1.c | 3 +- libunwind/src/config.h| 37 +++- libunwind/test/aix_signal_unwind.pass.sh.S| 2 +- libunwind/test/bad_unwind_info.pass.cpp | 1 - libunwind/test/forceunwind.pass.cpp | 1 - libunwind/test/frameheadercache_test.pass.cpp | 2 +- libunwind/test/signal_unwind.pass.cpp | 1 - libunwind/test/unwind_leaffunction.pass.cpp | 1 - 14 files changed, 146 insertions(+), 168 deletions(-) diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index 5551c7d4bef1c..3e4c06dc44520 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -13,7 +13,6 @@ #define __ADDRESSSPACE_HPP__ #include -#include #include #include @@ -672,7 +671,10 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, Dl_info dyldInfo; if (dladdr((void *)addr, &dyldInfo)) { if (dyldInfo.dli_sname != NULL) { - snprintf(buf, bufLen, "%s", dyldInfo.dli_sname); + size_t nameLen = strlen(dyldInfo.dli_sname); + size_t len = nameLen < (bufLen - 1) ? nameLen : (bufLen - 1); + memcpy(buf, dyldInfo.dli_sname, len); + buf[len] = '\0'; *offset = (addr - (pint_t) dyldInfo.dli_saddr); return true; } @@ -681,7 +683,9 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, uint16_t nameLen; char *funcName = getFuncNameFromTBTable(addr, nameLen, offset); if (funcName != NULL) { -snprintf(buf, bufLen, "%.*s", nameLen, funcName); +size_t len = nameLen < (bufLen - 1) ? nameLen : (bufLen - 1); +memcpy(buf, funcName, len); +buf[len] = '\0'; return true; } #else diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index e7be0d6d5d635..f0ca9ad51396b 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -12,8 +12,8 @@ #ifndef __DWARF_INSTRUCTIONS_HPP__ #define __DWARF_INSTRUCTIONS_HPP__ +#include #include -#include #include #include "DwarfParser.hpp" @@ -416,24 +416,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL +for (pint_t *t = sp; t > stack; --t) { + _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); } +#endif uint8_t opcode = addressSpace.get8(p++); sint_t svalue, svalue2; pint_t value; @@ -444,16 +442,15 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.getP(p); p += sizeof(pint_t); *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_deref: // pop stack, dereference, push result value = *sp--; *(++sp) = addressSpace.getP(value); - if (log) -fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n", + (uint64_t)value); break; case DW_OP_const1u: @@ -461,8 +458,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get8(p); p += 1; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
https://github.com/michael-kenzel updated https://github.com/llvm/llvm-project/pull/72040 >From 8c59516b8235049dc74e2496b9e1a1833d38f494 Mon Sep 17 00:00:00 2001 From: Michael Kenzel Date: Sat, 11 Nov 2023 22:09:05 +0100 Subject: [PATCH] [libunwind] Remove unnecessary dependencies on stdio.h for increased baremetal friendliness --- libunwind/src/AddressSpace.hpp| 10 +- libunwind/src/DwarfInstructions.hpp | 173 +++--- libunwind/src/DwarfParser.hpp | 2 +- libunwind/src/Unwind-EHABI.cpp| 2 +- libunwind/src/UnwindCursor.hpp| 78 libunwind/src/UnwindLevel1-gcc-ext.c | 1 - libunwind/src/UnwindLevel1.c | 1 - libunwind/src/config.h| 37 +++- libunwind/test/aix_signal_unwind.pass.sh.S| 2 +- libunwind/test/bad_unwind_info.pass.cpp | 1 - libunwind/test/forceunwind.pass.cpp | 1 - libunwind/test/frameheadercache_test.pass.cpp | 2 +- libunwind/test/signal_unwind.pass.cpp | 1 - libunwind/test/unwind_leaffunction.pass.cpp | 1 - 14 files changed, 145 insertions(+), 167 deletions(-) diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index 5551c7d4bef1c..3e4c06dc44520 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -13,7 +13,6 @@ #define __ADDRESSSPACE_HPP__ #include -#include #include #include @@ -672,7 +671,10 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, Dl_info dyldInfo; if (dladdr((void *)addr, &dyldInfo)) { if (dyldInfo.dli_sname != NULL) { - snprintf(buf, bufLen, "%s", dyldInfo.dli_sname); + size_t nameLen = strlen(dyldInfo.dli_sname); + size_t len = nameLen < (bufLen - 1) ? nameLen : (bufLen - 1); + memcpy(buf, dyldInfo.dli_sname, len); + buf[len] = '\0'; *offset = (addr - (pint_t) dyldInfo.dli_saddr); return true; } @@ -681,7 +683,9 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, uint16_t nameLen; char *funcName = getFuncNameFromTBTable(addr, nameLen, offset); if (funcName != NULL) { -snprintf(buf, bufLen, "%.*s", nameLen, funcName); +size_t len = nameLen < (bufLen - 1) ? nameLen : (bufLen - 1); +memcpy(buf, funcName, len); +buf[len] = '\0'; return true; } #else diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index e7be0d6d5d635..f0ca9ad51396b 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -12,8 +12,8 @@ #ifndef __DWARF_INSTRUCTIONS_HPP__ #define __DWARF_INSTRUCTIONS_HPP__ +#include #include -#include #include #include "DwarfParser.hpp" @@ -416,24 +416,22 @@ typename A::pint_t DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, const R ®isters, pint_t initialStackValue) { - const bool log = false; pint_t p = expression; pint_t expressionEnd = expression + 20; // temp, until len read pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd); expressionEnd = p + length; - if (log) -fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n", -(uint64_t)length); + _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n", + (uint64_t)length); pint_t stack[100]; pint_t *sp = stack; *(++sp) = initialStackValue; while (p < expressionEnd) { -if (log) { - for (pint_t *t = sp; t > stack; --t) { -fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); - } +#if _LIBUNWIND_TRACING_DWARF_EVAL +for (pint_t *t = sp; t > stack; --t) { + _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t)); } +#endif uint8_t opcode = addressSpace.get8(p++); sint_t svalue, svalue2; pint_t value; @@ -444,16 +442,15 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.getP(p); p += sizeof(pint_t); *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value); break; case DW_OP_deref: // pop stack, dereference, push result value = *sp--; *(++sp) = addressSpace.getP(value); - if (log) -fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value); + _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n", + (uint64_t)value); break; case DW_OP_const1u: @@ -461,8 +458,7 @@ DwarfInstructions::evaluateExpression(pint_t expression, A &addressSpace, value = addressSpace.get8(p); p += 1; *(++sp) = value; - if (log) -fprintf(stderr, "push 0x%"
[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)
michael-kenzel wrote: @arichardson as promised, I have rebased the changes. I'm not sure about the test failures, it would seem to me that they are unlikely to be caused by anything I did? https://github.com/llvm/llvm-project/pull/72040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits