Forum > Windows

optimized sources

<< < (36/179) > >>

_heinz:
made some short sample programs.... now I´m testing the application and debug....
heinz

_heinz:
the application read now the files init_data.xml and work_unit.sah.
from init_data.xml debug shows ----> in hostinfo
      m_nbytes   134217728.00000000   double

and here in apc_ipc.c
void APP_INIT_DATA::copy(const APP_INIT_DATA& a) {
    memcpy(this, &a, sizeof(APP_INIT_DATA));
    if (a.project_preferences) {
        project_preferences = strdup(a.project_preferences);  <----here
    }
}
project_preferences will not be filled.... hmm ?
----------------------------------
and here in boinc_api.c   app_init_data will be filled
int boinc_get_init_data(APP_INIT_DATA& app_init_data) {
    app_init_data = aid;     <----- here
    return 0;
}
how we can see --->
+      app_init_data   {major_version=0 minor_version=0 release=0 ...}   APP_INIT_DATA &
      m_nbytes   134217728.00000000   double
host_info m_nbytes is there obove
------------------------------------------------
        boinc_get_init_data( app_init_data );
        if ( !nographics_flag
         &&  (app_init_data.host_info.m_nbytes != 0)
         &&  (app_init_data.host_info.m_nbytes <= ( double ) (48 * 1024 * 1024)) )
            {
            #ifdef BOINC_APP_GRAPHICS
            fprintf( stderr, "Low memory machine... Disabling graphics.\n" );
            fprintf(
                stderr,
                "%f <= %f\n",
                app_init_data.host_info.m_nbytes,
                ( double ) 48 * 1024 * 1024 );
            fflush( stderr );
            nographics_flag = 1;
            #endif
            }

        #ifdef BOINC_APP_GRAPHICS
        if ( !nographics_flag )
            {
            run_stage = GRXINIT;
                #ifdef DYNAMIC_GRAPHICS
            retval = boinc_init_graphics_lib( worker, argv[0] );
                #else
            retval = boinc_init_graphics( worker );
                #endif
            run_stage = POSTINIT;
            }
        else
            #endif
            {
            run_stage = POSTINIT;
            retval = boinc_init();       <------ here it should run into
            if ( !retval ) worker();      <------ than to worker()
            }
---------------------
it goes to boinc_init()
boinc_lockfile will be read
+      filename   0x005d4014 "boinc_lockfile"   const char *
it goes now to ----->
    retval = boinc_parse_init_data_file();
    if (retval) {
        standalone = true;
    } else {
        retval = setup_shared_mem();
        if (retval) {
            fprintf(stderr, "Can't set up shared mem: %d\n", retval);
            standalone = true;
        }
    }
boinc_init is sucessful done and it go´s to worker()
there it goes to read_wu_state --->
       retval = read_wu_state();
the workunit will be assigned
+      this   "work_unit.sah"   std::basic_string<char,std::char_traits<char>,std::allocator<char> > * const
we open the file work_unit.sah
    // Open the file and load the first line
    FILE *fp = fopen(virtual_name, "r");
    if (!fp) return ERR_FOPEN;

    char buf[512];
    fgets(buf, 512, fp);
    fclose(fp);
--------------------------------------------
read 512 bytes into buf and close the file
+      buf   0x0012f1a0 "<workunit>
"   char [512]
+      physical_name   "work_unit.sah"   std::basic_string<char,std::char_traits<char>,std::allocator<char> > &
now we are in worker opened the file an come to --->
        retval = seti_parse_wu( f, analysis_state );    <------- here
        fclose( f );
-----------------------
it goes to seti.cpp
int seti_parse_wu( FILE *f, ANALYSIS_STATE &state )
then to -->
    retval = seti_parse_wu_header( f );
we come to xstring
   bool __CLR_OR_THIS_CALL _Grow(size_type _Newsize,
      bool _Trim = false)
      {   // ensure buffer is big enough, trim to size if _Trim is true
         if (max_size() < _Newsize)
         _String_base::_Xlen();   // result too long
      if (_Myres < _Newsize)
         _Copy(_Newsize, _Mysize);   // reallocate to grow
      else if (_Trim && _Newsize < _BUF_SIZE)
         _Tidy(true,   // copy and deallocate if trimming to small string
            _Newsize < _Mysize ? _Newsize : _Mysize);
      else if (_Newsize == 0)
         _Eos(0);   // new size is zero, just null terminate
      return (0 < _Newsize);   // return true only if more work to do
      }
new size is zero and it goes back
it goes now to seti_header.cpp ---->
int seti_parse_wu_header( FILE *f )
and there to the loops --->
    do
        {
        fgets( buf, 256, f );
        }
    while ( !feof( f ) && !xml_match_tag( buf, "<workunit_header" ) );

    buffer += buf;

    while ( fgets( buf, 256, f ) && !xml_match_tag( buf, "</workunit_header" ) )
        {
        buffer += buf;
        }

    buffer += buf;

    if ( wu ) delete wu;
    wu = new workunit( buffer );

    SETI_WU_INFO    temp( *wu );
    swi = temp;
    found = 1;
----------------------------------
we run into the loop to fill the buffer
+      buf   0x0012edc4 "<workunit_header>
"   char [256]
+      buffer   ""   std::basic_string<char,std::char_traits<char>,std::allocator<char> >
+      f   0x0061f590 {_ptr=0x00379aff "  <name>01mr99ab.14893.2848.703400.3.151</name>
  <group_info>
    <tape_info>
      <name>01mr99ab</name>
      <start_time>2451239.5778227</start_time>
      <last_block_time>2451239.5778227</last_block_time>
      <last_block_done>2848</last_block_done>
      <missed>0</missed>
      <tape_quality>0</tape_quality>
      <sb_id>0</sb_id>
    </tape_info>
    _iobuf *
----------------------------------------------
and fill the buffer till we found "</workunit_header" ---> means  end of header
the whole workunit is now read into the buffer --->
<workunit_header>
  <name>01mr99ab.14893.2848.703400.3.151
.....
<subband_desc>
  <number>151</number>
  <center>1418978879.8359</center>
  <base>1418974607.375</base>
  <sample_rate>9765.625</sample_rate>
</subband_desc>
<sb_id>0</sb_id>
</workunit_header>
----------------------------------------------------------------
we come now to --->
    if ( wu ) delete wu;
    wu = new workunit( buffer );
-----------
it goes to dbgnew.cpp --->allocate memory block
in it it swiches to dbg_heap.cpp
and there to ---> _nh_malloc_dbg_impl
extern "C" void * __cdecl _nh_malloc_dbg (
        size_t nSize,
        int nhFlag,
        int nBlockUse,
        const char * szFileName,
        int nLine
        )
{
        int errno_tmp = 0;
        void * pvBlk = _nh_malloc_dbg_impl(nSize, nhFlag, nBlockUse, szFileName, nLine, &errno_tmp); <--here

        if ( pvBlk == NULL && errno_tmp != 0 && _errno())
        {
            errno = errno_tmp; // recall, #define errno *_errno()
        }
        return pvBlk;
----------------------------------
and there we do the allocation
        for (;;)
        {
            /* do the allocation
             */
            pvBlk = _heap_alloc_dbg_impl(nSize, nBlockUse, szFileName, nLine, errno_tmp);

            if (pvBlk)
            {
                return pvBlk;
            }
            if (nhFlag == 0)
            {
                *errno_tmp = ENOMEM;
                return pvBlk;
            }

            /* call installed new handler */
            if (!_callnewh(nSize))
            {
                *errno_tmp = ENOMEM;
                return NULL;
            }

            /* new handler was successful -- try to allocate again */
        }
-----------------
we make the allocation and come back with
    void *res = _nh_malloc_dbg( cb, 1, nBlockUse, szFileName, nLine );

      res   0x0037ab20   void *
----------------------------------------
then back to seti_header.cpp
    wu = new workunit( buffer );    <------ here

    SETI_WU_INFO    temp( *wu );
    swi = temp;
    found = 1;
--------------------
debugger shows --->
&#135;      operator new returned   0x0037ab20   void *
+      buffer   "<workunit_header>
  <name>01mr99ab.14893.2848.703400.3.151</name>
  <group_info>
    <tape_info>
      <name>01mr99ab</name>
      <start_time>2451239.5778227</start_time>
      <last_block_time>2451239.5778227</last_block_time>
      <last_block_done>2848</last_block_done>
      <missed>0</missed>
      <tape_quality>0</tape_quality>
      <sb_id>0</sb_id>
    </tape_info>
    <nam   std::basic_string<char,std::char_traits<char>,std::allocator<char> >
+      wu   0x00000000 {id=??? name=0x00000010 <Bad Ptr> group_info={...} ...}   workunit_header *
+      db_table<workunit_header>   {table_name=0x005d7014 "workunit_header" me=??? _search_tag=0x005d7014 "workunit_header" ...}   db_table<workunit_header>
      id   CXX0030: Error: expression cannot be evaluated   
+      name   0x00000010 <Bad Ptr>   char [64]
+      group_info   {r={...} id=??? }   db_reference<workunit_grp,long>
+      subband_desc   {number=??? center=??? base=??? ...}   subband_description_t
      sb_id   CXX0030: Error: expression cannot be evaluated
------------------
and in it db_table looks not so well prepared I think-      db_table<workunit_header>   {table_name=0x005d7014 "workunit_header" me=??? _search_tag=0x005d7014 "workunit_header" ...}   db_table<workunit_header>
      track_mem<workunit_header>   {...}   track_mem<workunit_header>
+      table_name   0x005d7014 "workunit_header"   char * const
      me   CXX0030: Error: expression cannot be evaluated   
+      _search_tag   0x005d7014 "workunit_header"   char *
      _nfields   5   int
+      column_names   0x005d7914 char * const * const db_table<class workunit_header>::column_names   char * const [5]
      cursor   CXX0030: Error: expression cannot be evaluated
--------------------------------------------
we come to dbgheap.c  --->
                    RTCCALLBACK(_RTC_FuncCheckSet_hook,(0));
                    pHead = (_CrtMemBlockHeader *)_heap_alloc_base(blockSize);   <---- here
and call the function
--------------------------
      blockSize   7284   unsigned int
      nSize   7248   unsigned int
+      pHead   0x00000000 {pBlockHeaderNext=??? pBlockHeaderPrev=??? szFileName=??? ...}   _CrtMemBlockHeader *
-----------------
I believe _CrtMemBlockHeader *    has in szFileName a bad value
----------------------
it goes to malloc.c   ---->
    if (__active_heap == __SYSTEM_HEAP) {
        return HeapAlloc(_crtheap, 0, size ? size : 1);
----------------
      __active_heap   1   int
      _crtheap   0x00370000   void *
      size   7284   unsigned int
   
and HeapAlloc is called --->
it runs through it more than 100 always with the values obove.... then it crashes

all this is in seti_parse_wu
suddenly we get a eror --->
Unhandled exception at 0x7c91eddd in seti_boinc.exe: 0xC0000005: Access violation writing location 0x00030ffc.

in stderr.txt we find ----> Can't set up shared mem: -1
------------------------------------
 searching now
any suggestions ? ?

Urs Echternacht:
No translation necessary.
(Vorweg: Bei meinen zweisprachigen Kommentaren beachte bitte nur die in Deutsch, da ich die in Englisch nur zur Verständnis für alle hier eingefügt habe.)

--- Quote from: seti_britta on 04 Jul 2007, 10:03:44 pm ---the application read now the files init_data.xml and work_unit.sah.
from init_data.xml debug shows ----> in hostinfo
      m_nbytes   134217728.00000000   double
...
-----------------
we make the allocation and come back with
    void *res = _nh_malloc_dbg( cb, 1, nBlockUse, szFileName, nLine );

      res   0x0037ab20   void *
----------------------------------------
--- End quote ---
0x0037ab20 seems to be the end of space for the heap. Which values do go into the _nh_malloc_dbg(...) ?
(Soweit reicht wohl der Speicherbereich, den der Heap später belegen darf. Welche Werte führen den in _nh_malloc_dbg(...) zu diesem Ergebnis ?)

--- Quote ---then back to seti_header.cpp
...
+      subband_desc   {number=??? center=??? base=??? ...}   subband_description_t
      sb_id   CXX0030: Error: expression cannot be evaluated
------------------
--- End quote ---
The missing values seem to be filled in by templates, so this could be a debugger problem.
(Da die fehlenden Werte in Templates eingesetzt werden sollen, kann es sein, daß der Debugger Probleme hat, zu erkennen, was da drin stehen soll.)

--- Quote ---...
--------------------------------------------
we come to dbgheap.c  --->
                    RTCCALLBACK(_RTC_FuncCheckSet_hook,(0));
                    pHead = (_CrtMemBlockHeader *)_heap_alloc_base(blockSize);   <---- here
and call the function
--------------------------
      blockSize   7284   unsigned int
      nSize   7248   unsigned int <----- Ist das ein Tippfehler (siehe weiter unten) ?
+      pHead   0x00000000 {pBlockHeaderNext=??? pBlockHeaderPrev=??? szFileName=??? ...}   _CrtMemBlockHeader *
-----------------
I believe _CrtMemBlockHeader *    has in szFileName a bad value
----------------------
it goes to malloc.c   ---->
    if (__active_heap == __SYSTEM_HEAP) {
        return HeapAlloc(_crtheap, 0, size ? size : 1);
----------------
      __active_heap   1   int
      _crtheap   0x00370000   void *
      size   7284   unsigned int
--- End quote ---
So, the memory for the heap starts at 0x00370000 and ends at 0x0037ab19. The rights to write at that memoryarea are given. But how does that calculate to 7284 times space for unsigned int's (debug: 1+4+1) ?
(Das ist also der Speicherbereich, der für den Heap reserviert ist. Nur in diesem Speicherbereich haben wir die Schreibrechte. Aber wie passt das ganze mit den 7284 vorzeichenlosen Integer-Werten zusammen die da drauf passen sollen ? Hast Du mal nachgerechnet, ob das in der Regel und im Extremfall hinkommt ?)

--- Quote ---   
and HeapAlloc is called --->
it runs through it more than 100 always with the values obove.... then it crashes

all this is in seti_parse_wu
suddenly we get a eror --->
Unhandled exception at 0x7c91eddd in seti_boinc.exe: 0xC0000005: Access violation writing location 0x00030ffc.

in stderr.txt we find ----> Can't set up shared mem: -1
------------------------------------
 searching now
any suggestions ? ?

--- End quote ---
I give it a try, but i don't know if that helps much.
(Ich habs versucht, weiss aber leider nicht, ob Dir das viel hilft.)

Try to reproduce the error with the debugger. If that is possible, take a look at the dissassembly in the debugger. Check what commands were called before the error( at 0x7c91eddd ) happened. Try to go back to the last command called inside seti-code. Indentify what variables and calls are included and which one gets/produces the wrong write command.
(Versuche mal mit dem Disassembly des Debuggers "näher" an den Fehler heranzukommen. Identifiziere einmal welcher Befehl im Seti-Code zu dieser Fehlermeldung geführt hat. Welche Variablen sind genau beteiligt und führen zu dieser Zugriffsverletzung?)

No translation !
(Na, toll ausgerechnet mein "Lieblingsfehler": 0xC0000005.  >:(   (Den hab ich "gefressen" !) )

_heinz:
Merci Urs,
compiled the whole application new, will see if there are any differences. will post tomorrow more about it.

     blockSize   7284   unsigned int
      nSize   7248   unsigned int <----- Ist das ein Tippfehler (siehe weiter unten) ?

nein kein tippfehler
-----------------------
get a stack overflow....

regards heinz

_heinz:
if I compile I get 2 warings, as you can see in 'xml_match_tag' and 'xml_find_tag'
maybe this make the trouble.....
Code wird generiert...
c:\i\sc\seti\seti_boinc_2k3_2.2b-ben-joe\db\xml_util.cpp(663) : warning C4717: 'xml_match_tag': Rekursiv für alle Steuerelementpfade. Die Funktion verursacht einen Stapelüberlauf zur Laufzeit.
c:\i\sc\seti\seti_boinc_2k3_2.2b-ben-joe\db\xml_util.cpp(689) : warning C4717: 'xml_find_tag': Rekursiv für alle Steuerelementpfade. Die Funktion verursacht einen Stapelüberlauf zur Laufzeit.
Kompilieren...
------------------------------------------------------------------------------------------------------------------------
and here is the code ---->
// return true if the tag appears in the line
//
bool xml_match_tag(char* buf,  char* tag) {
    char tmp_tag[BUFSIZ]={'<',0};
    if (strlen(buf)==0) return false;
    if (tag[0] == '<') {
      strlcpy(tmp_tag,tag,BUFSIZ);
    } else {
      strlcat(tmp_tag,tag,BUFSIZ);
    }
    char *p=tmp_tag+strlen(tmp_tag);
    do {
      *(p--)=0;
    } while (isxmldelim(*p));
    while ((buf=strstr(buf,tmp_tag))) {
      if (isxmldelim(buf[strlen(tmp_tag)])) return true;
      buf++;
    }
    return false;
}


bool xml_match_tag(const std::string &s, char* tag)
{
   return xml_match_tag(s.c_str(),tag);
663 }    <----- here

size_t xml_find_tag( char* buf, char* tag) {
//       const char *buf0=buf; // OK
    char *buf0=buf;
    char tmp_tag[BUFSIZ]={'<',0};
    if (tag[0] == '<') {
      strlcpy(tmp_tag,tag,BUFSIZ);
    } else {
      strlcat(tmp_tag,tag,BUFSIZ);
    }
    char *p=tmp_tag+strlen(tmp_tag);
    do {
      *(p--)=0;
    } while (isxmldelim(*p));
    while ((buf=strstr(buf,tmp_tag))) {
      if (isxmldelim(buf[strlen(tmp_tag)])) return buf-buf0;
      buf++;
    }
    return strlen(buf0);
}

std::string::size_type xml_find_tag(const std::string &s, char* tag)
{
   std::string::size_type p=xml_find_tag(s.c_str(),tag);
   return (p!=strlen(s.c_str()))?p:(std::string::npos);
689 }      <------- here
----------------------------------------------------------------------------------------------------------
have anybody of you a idea to prevent this
your suggestions are welcome....
regards heinz

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version