vsnprintf exception and debugging

jubueche
Posts: 32
Joined: Sat Jan 19, 2019 4:03 pm

vsnprintf exception and debugging

Postby jubueche » Sun Feb 03, 2019 12:56 pm

Hello,

I am currently debugging a code example for the MSFT iot-sdk-c and I am getting the following exception over and over again and can't figure out what is going on:

Code: Select all

0x400d6431: _svfprintf_r at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/vfprintf.c:1529

0x4015a886: _vsnprintf_r at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/vsnprintf.c:72

0x4015a8c2: vsnprintf at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/vsnprintf.c:41

0x400ef3a2: STRING_construct_sprintf at /home/julian/eclipse-workspace/chaze-esp32/components/esp-azure/azure-iot-sdk-c/c-utility/src/strings.c:786

0x400e7e30: IoTHubClient_LL_UploadMultipleBlocksToBlob_Impl at /home/julian/eclipse-workspace/chaze-esp32/components/esp-azure/azure-iot-sdk-c/iothub_client/src/iothub_client_ll_uploadtoblob.c:911

0x400e6efd: IoTHubClientCore_LL_UploadMultipleBlocksToBlobEx at /home/julian/eclipse-workspace/chaze-esp32/components/esp-azure/azure-iot-sdk-c/iothub_client/src/iothub_client_core_ll.c:2595

0x400e58e6: IoTHubDeviceClient_LL_UploadMultipleBlocksToBlob at /home/julian/eclipse-workspace/chaze-esp32/components/esp-azure/azure-iot-sdk-c/iothub_client/src/iothub_device_client_ll.c:127

0x400914e6: upload_to_blob_block at /home/julian/eclipse-workspace/chaze-esp32/components/upload_to_blob_block/upload_to_blob_block.c:111

0x400d3d20: azure_task(void*) at /home/julian/eclipse-workspace/chaze-esp32/main/main.cpp:51

0x4008e741: vPortTaskWrapper at /home/julian/Documents/esp/esp-idf/components/freertos/port.c:403
I also tried debugging using my JLINK, but when I want to go to the vsnprintf.c file, the debugger can not find it, neither can I.
Why is there a path with a different user? Who is Ivan :) ?

I tried increasing the stack size but apparently, that wasn't the problem. I don't think this is a MSFT-sdk side problem, but rather my own.

This is the code-section where it fails:

Code: Select all

STRING_HANDLE STRING_construct_sprintf(const char* format, ...)
{
    STRING* result;

#ifdef STRINGS_C_SPRINTF_BUFFER_SIZE
    size_t maxBufSize = STRINGS_C_SPRINTF_BUFFER_SIZE;
    char buf[STRINGS_C_SPRINTF_BUFFER_SIZE];
#else
    size_t maxBufSize = 0;
    char* buf = NULL;
#endif

    if (format != NULL)
    {
        va_list arg_list;
        int length;
        va_start(arg_list, format);

        /* Codes_SRS_STRING_07_041: [STRING_construct_sprintf shall determine the size of the resulting string and allocate the necessary memory.] */
        length = vsnprintf(buf, maxBufSize, format, arg_list);
        va_end(arg_list);
        if (length > 0)
        {
            result = (STRING*)malloc(sizeof(STRING));
            if (result != NULL)
            {
                result->s = (char*)malloc(length+1);
                if (result->s != NULL)
                {
                    va_start(arg_list, format);
                    if (vsnprintf(result->s, length+1, format, arg_list) < 0)
                    {
                        /* Codes_SRS_STRING_07_040: [If any error is encountered STRING_construct_sprintf shall return NULL.] */
                        free(result->s);
                        free(result);
                        result = NULL;
                        LogError("Failure: vsnprintf formatting failed.");
                    }
                    va_end(arg_list);
                }
                else
                {
                    /* Codes_SRS_STRING_07_040: [If any error is encountered STRING_construct_sprintf shall return NULL.] */
                    free(result);
                    result = NULL;
                    LogError("Failure: allocation sprintf value failed.");
                }
            }
            else
            {
                LogError("Failure: allocation failed.");
            }
        }
        else if (length == 0)
        {
            result = (STRING*)STRING_new();
        }
        else
        {
            /* Codes_SRS_STRING_07_039: [If the parameter format is NULL then STRING_construct_sprintf shall return NULL.] */
            result = NULL;
            LogError("Failure: vsnprintf return 0 length");
        }
    }
    else
    {
        LogError("Failure: invalid argument.");
        result = NULL;
    }
    /* Codes_SRS_STRING_07_045: [STRING_construct_sprintf shall allocate a new string with the value of the specified printf formated const char. ] */
    return (STRING_HANDLE)result;
}

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: vsnprintf exception and debugging

Postby ESP_igrr » Mon Feb 04, 2019 10:00 am

Could you please paste the complete message you get from the panic handler (not just the backtrace, but everything starting from "Guru Meditation")? It will likely give extra clues as to what kind of error it is.

Regarding the missing source: vsnprintf is part of newlib C library, which is supplied in pre-compiled form. You can get the source code from https://github.com/espressif/newlib-esp32. Then you can use 'debug-prefix-map' feature of GDB to map the source code paths from the ones in the library to the ones on your computer.

jubueche
Posts: 32
Joined: Sat Jan 19, 2019 4:03 pm

Re: vsnprintf exception and debugging

Postby jubueche » Mon Feb 04, 2019 10:19 am

Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400014fd PS : 0x00060130 A0 : 0x800d6438 A1 : 0x3ffcabf0
A2 : 0x00000000 A3 : 0xfffffffc A4 : 0x000000ff A5 : 0x0000ff00
A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x00000000 A9 : 0x00000000
A10 : 0x00000000 A11 : 0x3ffcadf1 A12 : 0x00000000 A13 : 0x3ffb1ecc
A14 : 0x3ffb1659 A15 : 0x3ffb20f9 SAR : 0x00000004 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffff

Backtrace: 0x400014fd:0x3ffcabf0 0x400d6435:0x3ffcac00 0x4015a896:0x3ffcaf10 0x4015a8d2:0x3ffcafa0 0x400ef3b2:0x3ffcafe0 0x400e7e40:0x3ffcb030 0x400e6f01:0x3ffcb090 0x400e58ea:0x3ffcb0c0 0x400914e6:0x3ffcb0e0 0x400d3d24:0x3ffcb100 0x4008e741:0x3ffcb120

I have identified this line as where the error occurs:

Code: Select all

                                  STRING_HANDLE req_string = STRING_construct_sprintf("{\"isSuccess\":%s, \"statusCode\":%d, \"statusDescription\":\"%s\"}", ((httpResponse < 300) ? "true" : "false"), httpResponse, BUFFER_u_char(responseToIoTHub));
This is the function being called. I checked and repsonseToIoTHub is not NULL.

Code: Select all

STRING_HANDLE STRING_construct_sprintf(const char* format, ...)
{
    STRING* result;

#ifdef STRINGS_C_SPRINTF_BUFFER_SIZE
    size_t maxBufSize = STRINGS_C_SPRINTF_BUFFER_SIZE;
    char buf[STRINGS_C_SPRINTF_BUFFER_SIZE];
#else
    size_t maxBufSize = 0;
    char* buf = NULL;
#endif

    if (format != NULL)
    {
        va_list arg_list;
        int length;
        va_start(arg_list, format);

        /* Codes_SRS_STRING_07_041: [STRING_construct_sprintf shall determine the size of the resulting string and allocate the necessary memory.] */
        length = vsnprintf(buf, maxBufSize, format, arg_list);
        va_end(arg_list);
        if (length > 0)
        {
            result = (STRING*)malloc(sizeof(STRING));
            if (result != NULL)
            {
                result->s = (char*)malloc(length+1);
                if (result->s != NULL)
                {
                    va_start(arg_list, format);
                    if (vsnprintf(result->s, length+1, format, arg_list) < 0)
                    {
                        /* Codes_SRS_STRING_07_040: [If any error is encountered STRING_construct_sprintf shall return NULL.] */
                        free(result->s);
                        free(result);
                        result = NULL;
                        LogError("Failure: vsnprintf formatting failed.");
                    }
                    va_end(arg_list);
                }
                else
                {
                    /* Codes_SRS_STRING_07_040: [If any error is encountered STRING_construct_sprintf shall return NULL.] */
                    free(result);
                    result = NULL;
                    LogError("Failure: allocation sprintf value failed.");
                }
            }
            else
            {
                LogError("Failure: allocation failed.");
            }
        }
        else if (length == 0)
        {
            result = (STRING*)STRING_new();
        }
        else
        {
            /* Codes_SRS_STRING_07_039: [If the parameter format is NULL then STRING_construct_sprintf shall return NULL.] */
            result = NULL;
            LogError("Failure: vsnprintf return 0 length");
        }
    }
    else
    {
        LogError("Failure: invalid argument.");
        result = NULL;
    }
    /* Codes_SRS_STRING_07_045: [STRING_construct_sprintf shall allocate a new string with the value of the specified printf formated const char. ] */
    return (STRING_HANDLE)result;
}

jubueche
Posts: 32
Joined: Sat Jan 19, 2019 4:03 pm

Re: vsnprintf exception and debugging

Postby jubueche » Mon Feb 04, 2019 12:18 pm

Ok issue was a null pointer in the MSFT sdk. It works now.
Last edited by jubueche on Tue Sep 17, 2019 2:09 pm, edited 1 time in total.

fredtibo
Posts: 4
Joined: Mon Sep 09, 2019 2:03 pm

Re: vsnprintf exception and debugging

Postby fredtibo » Thu Sep 12, 2019 6:54 pm

I have the same probleme with the response when I upload a file using IoTHubClient_LL_UploadToBlob. The file is well uploaded in the blob storage but it crash at the exact same place has you.

You said that you have a null pointer and you fixed it. Can you tell me where and how you fixed it please.

Thanks,

jubueche
Posts: 32
Joined: Sat Jan 19, 2019 4:03 pm

Re: vsnprintf exception and debugging

Postby jubueche » Tue Sep 17, 2019 2:08 pm


Who is online

Users browsing this forum: No registered users and 102 guests