Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception.what() not a string #8716

Closed
6 tasks done
mhightower83 opened this issue Nov 16, 2022 · 5 comments
Closed
6 tasks done

exception.what() not a string #8716

mhightower83 opened this issue Nov 16, 2022 · 5 comments

Comments

@mhightower83
Copy link
Contributor

mhightower83 commented Nov 16, 2022

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: [ESP-01S]
  • Core Version: [80bf716]
  • Development Env: [Arduino IDE]
  • Operating System: [Ubuntu]

Settings in IDE

  • Module: [Generic ESP8266 Module]
  • Flash Mode: [dout]
  • Flash Size: [1MB]
  • lwip Variant: [v2 Lower Memory]
  • Reset Method: [nodemcu]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mhz]
  • Upload Using: [SERIAL]
  • Upload Speed: [921600 (serial upload only)

Problem Description

For the case of a missing try/catch around new, a secondary crash within postmortem occurs while processing the unhandled C++ Exception.

The second crash is caused when e.what() returns a value of 0x12.

__unhandled_exception( e.what() );

resulting in a new ESP exception in postmortem at
ets_printf_P(PSTR("\nUnhandled C++ exception: %S\n"), s_unhandled_exception);

MCVE Sketch

/*
   Build with Tools->C++ Exceptions: "enable"
*/
char *p = NULL;

void setup() {
  Serial.begin(115200);
  delay(100);
  Serial.printf("\nUp and running ...\n");

  // loops - crashing in postmortem
  p = new char[128000];

  if (p) {
    Serial.printf("\n%p, \"new\" worked, it should not have!\n", p);
  }
}

void loop() {}

Debug Messages

Up and running ...

User exception (panic/abort/assert)
--------------- CUT HERE FOR EXCEPTION DECODER ---------------

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

 ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset

@mcspr
Copy link
Collaborator

mcspr commented Nov 16, 2022

... #8717 as an alternative way of overloading new. note c++17 also has aligned ones, seems like a waste writing all of those yet again :/

std::bad_alloc::what() is indeed returning 0x12.

arduino8716 [1]> xtensa-lx106-elf-gdb --batch --ex "disassemble 'std::bad_alloc::what'" --ex "x 0x40204674" .pio/build/d1_mini/firmware.elf
Dump of assembler code for function std::bad_alloc::what() const:
   0x4020d614 <+0>:     l32r    a2, 0x40204674
   0x4020d617 <+3>:     ret.n
End of assembler dump.
0x40204674:     0x00000012

Here's the string, though

> xtensa-lx106-elf-objdump -s -j .irom.exceptiontext  ~/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/tools/sdk/lib/libstdc++-exc.a
...
bad_alloc.o:     file format elf32-xtensa-le

Contents of section .irom.exceptiontext:
 0000 7374643a 3a626164 5f616c6c 6f6300    std::bad_alloc.
...

(see toolchain .patch)

@mcspr
Copy link
Collaborator

mcspr commented Nov 16, 2022

this seems to fix the discarded address, just not sure why the rule(s) below try to put things in .text

diff --git a/tools/sdk/ld/eagle.app.v6.common.ld.h b/tools/sdk/ld/eagle.app.v6.common.ld.h
index 77c834ae..ed838918 100644
--- a/tools/sdk/ld/eagle.app.v6.common.ld.h
+++ b/tools/sdk/ld/eagle.app.v6.common.ld.h
@@ -181,8 +181,8 @@ SECTIONS
     *libgcc.a:_fixsfsi.o(.literal .text)
     *libgcc.a:_cmpdf2.o(.literal .text)
     *libgcc.a:_cmpsf2.o(.literal .text)
     *libstdc++.a:( .literal .text .literal.* .text.*)
-    *libstdc++-exc.a:( .literal .text .literal.* .text.*)
+    *libstdc++-exc.a:( .literal .text .literal.* .text.* .irom.exceptiontext)
     *libsmartconfig.a:(.literal .text .literal.* .text.*)
     *liblwip_gcc.a:(.literal .text .literal.* .text.*)
     *liblwip_src.a:(.literal .text .literal.* .text.*)

@mhightower83
Copy link
Contributor Author

@mcspr
Interesting options.
Your change to eagle.app.v6.common.ld.h worked for me.
Putting the strings into .irom0.text appears to land in the PROGMEM address range.
Thanks!

@mhightower83
Copy link
Contributor Author

@mcspr Also for me, removing the comma here allows things to work.

*(.irom.exceptiontext, .rodata.exceptiontext)

@mcspr
Copy link
Collaborator

mcspr commented Nov 24, 2022

(somewhat late comment, thanks for the fix!)

^ re above and Earles comment about ld, there is actually nothing about such syntax option in up-to-date binutils documentation.

https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_chapter/ld_toc.html

January 1994

vs.
https://sourceware.org/binutils/docs/ld/Input-Section-Basics.html

Nothing in the testsuite either; git log -p -- ./ld/testsuite/**.ld, search for , . gives nothing useful. Noticed this 'ordered' list, but not really sure of the difference between the two (manual sorting order?)

+  .got            : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) }

https://sourceware.org/git?p=binutils-gdb.git;a=tree;f=ld/testsuite;h=1f226f4c011ade55ee276991a21631a19ef675fd;hb=HEAD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants