Page 1 of 1

JTAG Optimized to unusable

Posted: Wed Oct 28, 2020 7:50 pm
by Scott.Bonomi
How do I limit/Prohibit the optimization in the IDF successfully . According to the GCC on line manual, __attribute__((optimize("O0"))) should stop all optimization in that module, When I get there with GDB and JTAG, The names are gone.
I do not see a strip statement in the build. It would be nice to be able to know what the code is doing.


Thread 2 hit Breakpoint 3, sendData (logName=<optimized out>, L_Data=<optimized out>) at ../main/SerialTasks.c:73
73 Osize = strlen(OutBuffer);
(gdb) list
68 void __attribute__((optimize("O0"))) sendData(const char* logName, const char* L_Data)
69 {
70 const int len = strlen(L_Data);
71 int Osize = 0;
72 ESP_LOGW("SD","Called with 0x%08x, for %d \n", (uint32_t)L_Data, len );
73 Osize = strlen(OutBuffer);
74 ESP_LOGW("SD","Buffer has %d \n", Osize );
75 // See if we can obtain the semaphore. If the semaphore is not available
76 // wait 10 ticks to see if it becomes free.
77 ESP_LOGW("SD","Called with ::%s:: tag ::%s:: \n", L_Data, logName );
78 if( xSemaphoreTake( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )

(gdb) print len
$1 = <optimized out>

Re: JTAG Optimized to unusable

Posted: Mon Nov 02, 2020 6:41 pm
by Scott.Bonomi
I see that no answer is forthcoming
changing to
OPTIMIZATION_FLAGS = -O0
in esp-idf/make/project.mk
had no effect on the optimizations either.

Re: JTAG Optimized to unusable

Posted: Tue Nov 03, 2020 2:28 am
by ESP_Sprite
Up to a point, I don't think there is much you can do... len is a constant, and instead of actually assigning it a register or memory location, I think gcc just happily substitutes the constant number instead. You may be able to do 'p strlen(L_Data)' instead.

Re: JTAG Optimized to unusable

Posted: Tue Nov 03, 2020 6:43 pm
by Scott.Bonomi
Yes, in this function, len is a const during each iteration of the function, but different for each instance of the function. It is not JUST len that is optimized out. All the incoming arguments are optimized out, as well as most, if not all, of the local variables which are put into registers. The register to variable mapping is not obvious, and I do not wish to start looking at assembly code if I have any choice. Trying to figure out why I was always getting my initial value back from a read of the SPI Bus, let to assumption that the compiler/optimizer was moving the initialization of the returned variable to after the call to spi_device_queue_trans() and not returning the byte read. That seems to have been affected by setting a pragma on optimization for that entire file. Without having unwound the file, it still seems to be removing the symbol table from the .elf file for anything considered local.

There should be a command line or pragma control for this, but I do not find one other than GCC_Optimize.