cURL / Mailing Lists / curl-library / Single Mail

curl-library

gdb trace in curl core

From: Chirag <chirag_at_cellcloud.com>
Date: Fri, 27 Sep 2002 14:27:54 +0530

Hi,

    Please may i know what does this core in CURL mean ? My function,
get_url_content_from_web is calling the curl_perform() function. I have 30
threads and the core as well as my function is given below. I had disabled
the TIMEOUT option. (What then will it take the default timeout as ?)

bash-2.03$ gdb mgateway core
GNU gdb 5.0
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.8"...(no debugging symbols
found)...

warning: exec file is newer than core file.
Core was generated by `./mgateway'.
Program terminated with signal 9, Killed.
Reading symbols from /usr/lib/libpthread.so.1...(no debugging symbols
found)...done.
Loaded symbols for /usr/lib/libpthread.so.1
Reading symbols from /usr/local/lib/libgdbm.so.2...(no debugging symbols
found)...done.
Loaded symbols for /usr/local/lib/libgdbm.so.2
Reading symbols from /usr/local/lib/libcurl.so.2...done.
Loaded symbols for /usr/local/lib/libcurl.so.2
Reading symbols from /usr/lib/libdl.so.1...done.
Loaded symbols for /usr/lib/libdl.so.1
Reading symbols from /usr/lib/libsocket.so.1...done.
Loaded symbols for /usr/lib/libsocket.so.1
Reading symbols from /usr/lib/libnsl.so.1...done.
Loaded symbols for /usr/lib/libnsl.so.1
Reading symbols from /oracle/oracle8i/lib/libclntsh.so.8.0...done.
Loaded symbols for /oracle/oracle8i/lib/libclntsh.so.8.0
Reading symbols from /oracle/oracle8i/lib/libwtc8.so...done.
Loaded symbols for /oracle/oracle8i/lib/libwtc8.so
Reading symbols from /usr/lib/libgen.so.1...done.
Loaded symbols for /usr/lib/libgen.so.1
Reading symbols from /usr/lib/libsched.so.1...done.
Loaded symbols for /usr/lib/libsched.so.1
Reading symbols from /usr/lib/libm.so.1...done.
Loaded symbols for /usr/lib/libm.so.1
Reading symbols from /usr/lib/libc.so.1...done.
Loaded symbols for /usr/lib/libc.so.1
Reading symbols from /usr/local/lib/libgcc_s.so.1...done.
Loaded symbols for /usr/local/lib/libgcc_s.so.1
Reading symbols from /usr/lib/libmp.so.2...done.
Loaded symbols for /usr/lib/libmp.so.2
Reading symbols from /usr/lib/libaio.so.1...done.
Loaded symbols for /usr/lib/libaio.so.1
Reading symbols from
/usr/platform/SUNW,Sun-Fire-280R/lib/libc_psr.so.1...done.
Loaded symbols for /usr/platform/SUNW,Sun-Fire-280R/lib/libc_psr.so.1
Reading symbols from /usr/lib/libthread.so.1...done.
Loaded symbols for /usr/lib/libthread.so.1
#0 Curl_pgrsUpdate (conn=0x13ca58) at progress.c:193
193 int nowindex = data->progress.speeder_c% CURR_TIME;
(gdb) where
#0 Curl_pgrsUpdate (conn=0x13ca58) at progress.c:193
#1 0xff3246d0 in Transfer (c_conn=0x13ca58) at transfer.c:848
#2 0xff325690 in Curl_perform (data=0x34ce30) at transfer.c:933
#3 0x1dac4 in get_url_content_from_web ()
#4 0x1f9d0 in process_curl_queue ()
#5 0x3072c in start_read_curl_queue_thread ()
(gdb) bt
#0 Curl_pgrsUpdate (conn=0x13ca58) at progress.c:193
#1 0xff3246d0 in Transfer (c_conn=0x13ca58) at transfer.c:848
#2 0xff325690 in Curl_perform (data=0x34ce30) at transfer.c:933
#3 0x1dac4 in get_url_content_from_web ()
#4 0x1f9d0 in process_curl_queue ()
#5 0x3072c in start_read_curl_queue_thread ()
(gdb)

  struct MemoryStruct {
    unsigned char *memory;
    size_t size;
  };

  typedef struct CURL_MEM CURL_MEM;
 struct CURL_MEM {
  int err_no;
  struct MemoryStruct mems;
 };

  size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void
*data)
  {
    register int realsize = size * nmemb;
    struct MemoryStruct *mem = (struct MemoryStruct *)data;

    mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1);
    if (mem->memory) {
     memcpy(&(mem->memory[mem->size]), ptr, realsize);
      mem->size += realsize;
      mem->memory[mem->size] = 0;
   }
    return realsize;
 }

CURL_MEM get_url_content_from_web(unsigned char * url_to_be_fetched, int
timeout, int answer)
{
   CURL *curl_handle;
   CURLcode res;
   //char * http_header=NULL;
   char http_header[HEADER_SIZE];
   char * http_body=NULL;

   struct MemoryStruct chunk;
   CURL_MEM curl_mem;

   char http[20];
   int status;

    chunk.memory=NULL; /* we expect realloc(NULL, size) to work */
    chunk.size = 0; /* no data at this point */

    log_debug(LOG_DEBUG_LEVEL,"In get_url_content_from_web with url(%s)\n",
url_to_be_fetched);
 //printf("URL to be retrieved by CURL is %s\n",url_to_be_fetched);

    // init the curl session
    curl_handle = curl_easy_init();

 // specify URL to get
    curl_easy_setopt(curl_handle, CURLOPT_URL, url_to_be_fetched);
 // Set option for HTTP Headers
 curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, TRUE);
 curl_easy_setopt(curl_handle, CURLOPT_HEADER, TRUE);
 //Set follow-up if the page is redirected
 curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 2);
 //Set conn. timeout (Trying after commenting out)
 //curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, timeout);
 // WMCB collects the URL content into a buffer
 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);

    // we pass our 'chunk' struct to the callback function
    curl_easy_setopt(curl_handle, CURLOPT_FILE, (void *)&chunk);

    // get it!
 printf("------>Before CURL Perform\n");
     res = curl_easy_perform(curl_handle);
  printf("------>After CURL Perform\n");
 curl_mem.err_no = res;

 // cleanup curl stuff originally it was here
    //curl_easy_cleanup(curl_handle);
 printf("Checking if res == 0\n");
  if(res != 0)//Could be some CURL error
  {
   printf("In res !=0\n");
   chunk.memory = (unsigned char *) malloc (ERROR_SIZE);
   bzero(chunk.memory,ERROR_SIZE);
   log_debug(LOG_DEBUG_LEVEL, "::TRACK_CURL_ERR::res(%d)\n" ,res);
   strcpy(chunk.memory,curl_error_codes(res));
   chunk.size = strlen(chunk.memory);
   goto END;
  }

 printf("Checking if answer or chunk is NULL\n");
 //If no SMS response is asked or the chunk has nothing
 if((answer == 0) || (chunk.size == 0) || (chunk.memory == NULL))
 {
  printf("In answer/chunk null\n");
  chunk.memory = (unsigned char *) malloc (strlen("ok")+1);
  bzero(chunk.memory, strlen("ok")+1);
  log_debug(LOG_DEBUG_LEVEL, "::TRACK_CHUNK_ANS_NULL::res(%d)\n" ,res);
  strcpy(chunk.memory, "ok");
  chunk.size = strlen(chunk.memory);
  printf("Either answer(0) or chunk is null\n");
  goto END;
 }

   printf("Chunk size is %d\n",chunk.size);
 //Trying static allocation
 //http_header = (char *) malloc (HEADER_SIZE);
 bzero(http_header, HEADER_SIZE);

STRIP_HEAD:
 printf("Under strip head tag\n");
 sscanf(chunk.memory, "%[^\r\n]", http_header);
 printf("#### HTTP HEADER (%s)\n", http_header);

 http_body = (char *)strstr(chunk.memory, "\r\n\r\n");
 if(http_body == NULL) {
  chunk.memory = (unsigned char *) malloc (strlen("ok")+1);
  bzero(chunk.memory, strlen("ok")+1);
  strcpy(chunk.memory,"ok");
  chunk.size = strlen(chunk.memory);

 } else {
  printf("Getting http_header\n");
  sscanf(http_header,"%s %d",http,&status);

   printf("Header is %s and status is %d\n",http,status);
  if(status >= 301 && status <= 304) {
    printf("The header status is ########### %d ############\n",status);
   chunk.memory = (unsigned char *) malloc (strlen(http_body)+1);
   bzero(chunk.memory, strlen(http_body)+1);
   strcpy(chunk.memory, http_body+strlen("\r\n\r\n"));
   chunk.size = strlen(chunk.memory);
   goto STRIP_HEAD;
  } else if(status == 200 || status == 202) { //Success
   chunk.memory = (unsigned char *) malloc (strlen(http_body)+1);
   bzero(chunk.memory, strlen(http_body)+1);
   strcpy(chunk.memory, http_body+strlen("\r\n\r\n"));
   chunk.size = strlen(chunk.memory);
   printf("#### HTTP BODY Chunk size (%d) and content (%s)\n", chunk.size,
chunk.memory);
   if(chunk.size == 0) {
              chunk.memory = (unsigned char *) malloc (strlen("ok")+1);
              bzero(chunk.memory, strlen("ok")+1);
                 strcpy(chunk.memory,"ok");
                 chunk.size = strlen(chunk.memory);
            }
  } else if(status >= 1 && status <= 52) { //CURL Errors
   chunk.memory = (unsigned char *) malloc (ERROR_SIZE);
   bzero(chunk.memory,ERROR_SIZE);
   strcpy(chunk.memory,curl_error_codes(status));
   chunk.size = strlen(chunk.memory);
  } else {
   chunk.memory = (unsigned char *) malloc (strlen(http_header)+1);
   bzero(chunk.memory,strlen(http_header)+1);
   strcpy(chunk.memory, http_header);
   chunk.size = strlen(chunk.memory);
  }
 }

END:
 printf("Copying chunk.memory and chunk.size\n");
  curl_mem.mems.memory = chunk.memory;
  curl_mem.mems.size = chunk.size;

 //Trying to cleanup curl at the end
  curl_easy_cleanup(curl_handle);
 return(curl_mem);
}

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2002-09-27