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 !
  • Code: Untitled.asm Select all

    
    void* CSFindMsgRXEntry(uint32_t  rx_entry)
    {
    0: 004136 entry a1, 32
    void* p = MbaseMessageFind(rx_entry, DST_RX, MSG_TYPE_NORM);
    3: 02ad mov.n a10, a2
    5: 01a0c2 movi a12, 1
    8: 00a0b2 movi a11, 0
    b: 000081 l32r a8, fffc000c <CSFindMsgRXEntry+0xfffc000c>
    e: 0008e0 callx8 a8
    11: 0a2d mov.n a2, a10
    if(p)
    13: 9a8c beqz.n a10, 20 <CSFindMsgRXEntry+0x20>
    {
    printf("CSFindMsgRXEntry - FOUND NORMAL !!! %p\n",p);
    15: 0abd mov.n a11, a10
    17: 0000a1 l32r a10, fffc0018 <CSFindMsgRXEntry+0xfffc0018>
    1a: 000081 l32r a8, fffc001c <CSFindMsgRXEntry+0xfffc001c>
    1d: 0008e0 callx8 a8
    }
    return p;
    }
    20: 0020c0 memw
    23: f01d retw.n

    void* MbaseMessageFind(MSG_ENTRY_T entry, RX_TX_DEST_T rtx, EXPR_NORM_T st)
    {
    0: 004136 entry a1, 32
    /* look for a message that matches the mailbox id we're interested in */
    void* pMbaseList;
    pMbaseList = getMbaseList(entry,rtx,st);
    3: 04cd mov.n a12, a4
    5: 03bd mov.n a11, a3
    7: 20a220 or a10, a2, a2
    a: 000081 l32r a8, fffc000c <MbaseMessageFind+0xfffc000c>
    d: 0008e0 callx8 a8
    if(pMbaseList)
    10: 4a9c beqz.n a10, 28 <MbaseMessageFind+0x28>
    {
    MBASE_MSG_T* hdr = pMbaseList->pMbaseMsgList;
    12: 0aa8 l32i.n a10, a10, 0
    if(hdr)
    14: 0a9c beqz.n a10, 28 <MbaseMessageFind+0x28>
    return (MBASE_MSG_HANDLE_T*)(1 + hdr); /* ONE (1) struct further */
    16: 2acb addi.n a2, a10, 12
    {
    MBASE_MSG_HANDLE_T* r=MbaseHandleFromPtr(hdr);
    //JUST FOR DEBUG
    printf ("MbaseMessageFind : FOUND-one-in %p - %p \n",hdr,r);
    18: 0abd mov.n a11, a10
    1a: 0000a1 l32r a10, fffc001c <MbaseMessageFind+0xfffc001c>
    1d: 20c220 or a12, a2, a2
    20: 000081 l32r a8, fffc0020 <MbaseMessageFind+0xfffc0020>
    23: 0008e0 callx8 a8
    //JUST FOR DEBUG
    return r;
    26: 02ad mov.n a10, a2
    }
    }
    return NULL;
    }
    28: 0a2d mov.n a2, a10
    2a: 0020c0 memw
    2d: f01d retw.n
    [/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: No registered users and 2 guests