return value bad !

noel_v1970
Posts: 2
Joined: Wed Mar 20, 2024 10:48 am

return value bad !

Postby noel_v1970 » Thu Mar 21, 2024 10:09 am

Hello

We are using esp-idf5.1.2 and an ESP32 CPU.

we are experiencing a very weird problem...
A return value of a c-function is BAD , the function returns a pointer, this pointer is ok before the return, after the return it gets zero (most of the time) .

{all is running from the main-app ! ( single task) code included below }
{ i've included 'decompiled' code ... below too }


I have function CSFindMsgRXEntry, that calls MbaseMessageFind directly ( returning a void *)
if I printf the pointer before the return I get normal value, if I print it after the function the pointer is zeroed.


if you look at the code and prints ... how can it be that MbaseMessageFind prints a value while the CSFindMsgRXEntry is printing nothing ?
{ yfi - normal printf are not there .. but this has same result }


logged print-outs ( in terminal) !!!!

MbaseMessageFind : FOUND-one-in 0x3ffbd7d8 - 0x3ffbd7e4
MbaseMessageFind : FOUND-one-in 0x3ffbd7d8 - 0x3ffbd7e4
MbaseMessageFind : FOUND-one-in 0x3ffbd7d8 - 0x3ffbd7e4
MbaseMessageFind : FOUND-one-in 0x3ffbd7d8 - 0x3ffbd7e4
CSFindMsgRXEntry - FOUND NORMAL !!! 0x3ffbd7e4 count:0

How can this be the case looking at the code below ?




Normal flow would be
MbaseMessageFind : FOUND-one-in 0x3ffbd7d8 - 0x3ffbd7e4
CSFindMsgRXEntry - FOUND NORMAL !!! 0x3ffbd7e4

MbaseMessageFind : FOUND-one-in 0x3ffbd7d8 - 0x3ffbd7e4
CSFindMsgRXEntry - FOUND NORMAL !!! 0x3ffbd7e4





Anyone a HINT ? who has more info ..

details what to check ? correct ? ( compiler settings ?)

As said before code can be found below !

Regards Noel



some additional info .. just in case... it might bring something

I (0) cpu_start: App cpu up.
I (921) esp_psram: SPI SRAM memory test OK
I (929) cpu_start: Pro cpu start user code
I (929) cpu_start: cpu freq: 240000000 Hz
I (929) cpu_start: Application information:
I (932) cpu_start: Project name: basic
I (937) cpu_start: App version: NOELV-105-g8187995
I (944) cpu_start: Compile time: Mar 21 2024 07:30:18
I (950) cpu_start: ELF file SHA256: 417a7d3875f3b490...
I (956) cpu_start: ESP-IDF: v5.1.2-dirty
I (961) cpu_start: Min chip rev: v0.0
I (966) cpu_start: Max chip rev: v3.99
I (971) cpu_start: Chip rev: v3.1
I (976) heap_init: Initializing. RAM available for dynamic allocation:
I (983) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (989) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (995) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (1001) heap_init: At 3FFC78F8 len 00018708 (97 KiB): DRAM
I (1007) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (1014) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (1020) heap_init: At 40099788 len 00006878 (26 KiB): IRAM
I (1027) esp_psram: Adding pool of 4095K of PSRAM memory to heap allocator
I (1035) spi_flash: detected chip: generic
I (1039) spi_flash: flash io: dio
I (1043) coexist: coex firmware version: b6d5e8c
I (1049) app_start: Starting scheduler on CPU0
(1053) app_start: Starting scheduler on CPU1
32mI (1053) main_task: Started on CPU0


Code: Select all


//
// snip...
//

void* MbaseMessageFind(MSG_ENTRY_T entry, RX_TX_DEST_T rtx, EXPR_NORM_T st)
{
     /* look for a message that matches the mailbox id we're interested in */
	void* pMbaseList;
	pMbaseList = getMbaseList(entry,rtx,st);
	if(pMbaseList) 
	{
		MBASE_MSG_T* hdr  = pMbaseList->pMbaseMsgList;
		if(hdr)
		{
			MBASE_MSG_HANDLE_T* r=MbaseHandleFromPtr(hdr);
//JUST FOR DEBUG
			printf ("MbaseMessageFind : FOUND-one-in %p - %p \n",hdr,r);
//JUST FOR DEBUG
			return r;
		}
	}
	return NULL;
}



void* CSFindMsgRXEntry(uint32_t  rx_entry)
{
	void* p = MbaseMessageFind(rx_entry, DST_RX, MSG_TYPE_NORM);
	if(p)
	{
		printf("CSFindMsgRXEntry - FOUND NORMAL !!! %p\n",p);
	}
	return p;
}



disassembled code !
    1. void* CSFindMsgRXEntry(uint32_t  rx_entry)
    2. {
    3.    0:   004136          entry   a1, 32
    4.     void* p = MbaseMessageFind(rx_entry, DST_RX, MSG_TYPE_NORM);
    5.    3:   02ad        mov.n   a10, a2
    6.    5:   01a0c2          movi    a12, 1
    7.    8:   00a0b2          movi    a11, 0
    8.    b:   000081          l32r    a8, fffc000c <CSFindMsgRXEntry+0xfffc000c>
    9.    e:   0008e0          callx8  a8
    10.   11:   0a2d        mov.n   a2, a10
    11.     if(p)
    12.   13:   9a8c        beqz.n  a10, 20 <CSFindMsgRXEntry+0x20>
    13.     {
    14.         printf("CSFindMsgRXEntry - FOUND NORMAL !!! %p\n",p);
    15.   15:   0abd        mov.n   a11, a10
    16.   17:   0000a1          l32r    a10, fffc0018 <CSFindMsgRXEntry+0xfffc0018>
    17.   1a:   000081          l32r    a8, fffc001c <CSFindMsgRXEntry+0xfffc001c>
    18.   1d:   0008e0          callx8  a8
    19.     }
    20.     return p;
    21. }
    22.   20:   0020c0          memw
    23.   23:   f01d        retw.n
    24.  
    25. void* MbaseMessageFind(MSG_ENTRY_T entry, RX_TX_DEST_T rtx, EXPR_NORM_T st)
    26. {
    27.    0:   004136          entry   a1, 32
    28.     /* look for a message that matches the mailbox id we're interested in */
    29.     void* pMbaseList;
    30.     pMbaseList = getMbaseList(entry,rtx,st);
    31.    3:   04cd        mov.n   a12, a4
    32.    5:   03bd        mov.n   a11, a3
    33.    7:   20a220          or  a10, a2, a2
    34.    a:   000081          l32r    a8, fffc000c <MbaseMessageFind+0xfffc000c>
    35.    d:   0008e0          callx8  a8
    36.     if(pMbaseList)
    37.   10:   4a9c        beqz.n  a10, 28 <MbaseMessageFind+0x28>
    38.     {
    39.         MBASE_MSG_T* hdr  = pMbaseList->pMbaseMsgList;
    40.   12:   0aa8        l32i.n  a10, a10, 0
    41.         if(hdr)
    42.   14:   0a9c        beqz.n  a10, 28 <MbaseMessageFind+0x28>
    43.     return (MBASE_MSG_HANDLE_T*)(1 + hdr); /* ONE (1) struct further */
    44.   16:   2acb        addi.n  a2, a10, 12
    45.         {
    46.             MBASE_MSG_HANDLE_T* r=MbaseHandleFromPtr(hdr);
    47. //JUST FOR DEBUG
    48.             printf ("MbaseMessageFind : FOUND-one-in %p - %p \n",hdr,r);
    49.   18:   0abd        mov.n   a11, a10
    50.   1a:   0000a1          l32r    a10, fffc001c <MbaseMessageFind+0xfffc001c>
    51.   1d:   20c220          or  a12, a2, a2
    52.   20:   000081          l32r    a8, fffc0020 <MbaseMessageFind+0xfffc0020>
    53.   23:   0008e0          callx8  a8
    54. //JUST FOR DEBUG
    55.             return r;
    56.   26:   02ad        mov.n   a10, a2
    57.         }
    58.     }
    59.     return NULL;
    60. }
    61.   28:   0a2d        mov.n   a2, a10
    62.   2a:   0020c0          memw
    63.   2d:   f01d        retw.n
    64. [/list]

noel_v1970
Posts: 2
Joined: Wed Mar 20, 2024 10:48 am

Re: return value bad !

Postby noel_v1970 » Fri Mar 22, 2024 4:48 am

Hello ,


found the issue (cut and past bug...) !

So no need to investigate more time...

Solved !

Thanks

Who is online

Users browsing this forum: Baidu [Spider] and 76 guests