1999Q2/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: [MUD&#45;Dev] How to debug a method taking a variable list of arguments? -->
<!--X-From-R13: Pra Uerrne <terrneNploreuvtujnl.arg> -->
<!--X-Date: Sun, 13 Jun 1999 00:01:33 &#45;0700 -->
<!--X-Message-Id: 37634E53.3BA3757C#cyberhighway,net -->
<!--X-Content-Type: text/plain -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, [MUD-Dev] How to debug a method taking a variable list of argu</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:greear#cyberhighway,net">
</head>
<body background="/backgrounds/paperback.gif" bgcolor="#ffffff"
      text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000">

  <font size="+4" color="#804040">
    <strong><em>MUD-Dev<br>mailing list archive</em></strong>
  </font>
      
<br>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
<br clear=all><hr>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->

Date:&nbsp;
[&nbsp;<a href="msg00793.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00795.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00802.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00801.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00794">Author</A>
&nbsp;|&nbsp;<A HREF="#00794">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00794">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>[MUD-Dev] How to debug a method taking a variable list of arguments?</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: "<A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A>" &lt;<A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A>&gt;</LI>
<LI><em>Subject</em>: [MUD-Dev] How to debug a method taking a variable list of arguments?</LI>
<LI><em>From</em>: Ben Greear &lt;<A HREF="mailto:greear#cyberhighway,net">greear#cyberhighway,net</A>&gt;</LI>
<LI><em>Date</em>: Sat, 12 Jun 1999 23:23:15 -0700</LI>
<LI><em>Newsgroups</em>: comp.lang.c,comp.lang.c++</LI>
<LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
<LI><em>Sender</em>: <A HREF="mailto:greear#burrito,cyberhighway.net">greear#burrito,cyberhighway.net</A></LI>
<LI><em>Sender</em>: <A HREF="mailto:mud-dev-admin#kanga,nu">mud-dev-admin#kanga,nu</A></LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
This code is C++, but I figure that the c folks might have hit this
problem too.

I'm trying to pass a list of variable arguments through several methods.
For one reason or another, it's not working right, and I'm having a hard
time getting gdb or any other method to figure out why.

Anyone got any ideas on how to print out the addresses of the variable
args that are being sent in with gdb?  Any other information I
might find useful?


In case someone wants to look at the code I'm working on, here it is.

/** Returns &lt; 0 on error */
int move(critter&amp; pc, int i_th, const char* direction, short do_followers, 
         room&amp; rm, int&amp; is_dead) {
   ...

         mudlog &lt;&lt; "DIR_ADDR: " &lt;&lt; (void*)(direction) &lt;&lt; endl;
         rm.doEmote(pc, Selectors::instance().CC_mob_entry_allow, 
                    Selectors::instance().CC_mob_entry_deny,
                    CS_LEAVES_SPRINTF, direction);

   ...
}//move


//This is the method called above.

int room::doEmote(critter&amp; pc, CSelectorColl&amp; includes,
                  CSelectorColl&amp; denies, CSentryE cs_entry, ...) {
   Cell&lt;critter*&gt; cll(critters);
   critter* ptr;
   String buf(100);
   String buf2(100);

   va_list argp;
   va_start(argp, cs_entry);

   while ((ptr = cll.next())) {
      if (!(denies.matches(ptr, &amp;pc))) {
         if (mudlog.ofLevel(DBG)) {
            mudlog &lt;&lt; "room::doEmote, not denied." &lt;&lt; endl;
         }
         if (includes.matches(ptr, &amp;pc)) {
            if (mudlog.ofLevel(DBG)) {
               mudlog &lt;&lt; "room::doEmote, includes matched." &lt;&lt; endl;
            }

//NOTE: the cstr(cs_entry, *ptr) returns a constant string.  In the case I
// am testing, it will be:  "leaves %s."
// I have verified that I am getting the correct string.

            Sprintf(buf, cstr(cs_entry, *ptr), argp);

//ERROR: after this buf is corrupted, starting where the %s string should
// have been appended.

            mudlog &lt;&lt; endl &lt;&lt; "buf -:" &lt;&lt; buf &lt;&lt; ":-" &lt;&lt; endl &lt;&lt; endl;
            Sprintf(buf2, "%S %S", pc.getName(ptr-&gt;SEE_BIT), &amp;buf);
            ptr-&gt;show(buf2);
         }//if
      }//if
   }//while
   va_end(argp);
   return 0;
}//doEmote


//Here is the Sprintf method:
// I have added some debugging info trying to figure out what is wrong.  What
// is clear is that the pointer is not what I expected.  I have no idea why.

              /* friend functions */

void Sprintf(String&amp; targ, const char* string, ... ) {
   va_list ap;
   int i = 0;
   va_start(ap, string);
   int num = 0;
   String buf(100);
   int s_len;
   char* tmp_chr_str;
   String* tmp_str;

   targ = "\0"; //initialize targ

   for (i = 0; string[i]; ) {
      if (string[i] == '%') {
         i++;
         if (string[i] != '%') {
            switch (string[i]) {
               case 'i':    /* int */  
                  targ.Append(va_arg(ap, int));
                  break;
               case 'I':    /* ignore */
                  va_arg(ap, void*);
                  // Do nothing with it!!
                  break;
               case 'd':     /* long, turn it into an int */
                  targ.Append(va_arg(ap, int));
                  break;
               case 's':      /* char * */
                  if ((tmp_chr_str = va_arg(ap, char *))) {

//ERROR shows up here:
//NOTE:  tmp_chr_str is NOT the same as the:  direction  string passed in earlier.

                     LOGFILE &lt;&lt; "Sprintf: got string: " &lt;&lt; (void*)(tmp_chr_str) &lt;&lt; endl;
                     targ.Append(tmp_chr_str);
                  }//if
                  break;
               case 'p':    /* pointer */
                  targ.appendHex(va_arg(ap, long));
                  break;
               case 'S':      /* String */
                  if ((tmp_str = va_arg(ap, String *))) {
                     targ.Append(*tmp_str);
                  }//if
                  break;
               case 'P':      /* pad w/spaces */
                  i++; //looking at first number now
                  if (isdigit(string[i+1])) { //two digits?
                     if (isdigit(string[i])) { //it should be
                        num = 10 * ((int)(string[i]) - 48);
                        num += (int)(string[i+1]) - 48;
                     }//if
                     else {
                        LOGFILE.log(ERR, 
                                    "ERROR:  Sprintf, case 'P', first not an int\n");
                     }
                  }//if two digits
                  else {
                     LOGFILE.log(ERR,
                                 "ERROR:  Sprintf, case 'P', second not an int\n");
                  }
                  i += 2; //now pointing to next valid letter
                  
                  s_len = targ.Strlen();
                  while (s_len &lt; num) {
                     targ.Append(" ");  //pad another space
                     s_len++;
                  }//while
                  i--;  //slight hack
                  break;
               default:
                  targ.Assert(FALSE, "ERROR: default called in Sprintf.\n");
            }//switch
            i++;
         }//if
         else { //
            i++;
            targ.Append("%");
         }//else
      }//if
      else {
         targ.Append(string[i]);
         i++;
      }//else
   }//for
   va_end(ap);
}//Sprintf



-- 
Ben Greear (greear#cyberhighway,net)  <A  HREF="http://scry.wanfear.com/~greear">http://scry.wanfear.com/~greear</A> 
Author of ScryMUD:  scry.wanfear.com 4444        (Released under GPL)
<A  HREF="http://scry.wanfear.com">http://scry.wanfear.com</A>


_______________________________________________
MUD-Dev maillist  -  MUD-Dev#kanga,nu
<A  HREF="http://www.kanga.nu/lists/listinfo/mud-dev">http://www.kanga.nu/lists/listinfo/mud-dev</A>


</PRE>

<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<HR>
<!--X-Follow-Ups-End-->
<!--X-References-->
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00793.html">Re: [MUD-Dev] Game Economies</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00795.html">Re: [MUD-Dev] How to debug a method taking a variable list of arguments?</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00802.html">[MUD-Dev] Twisted Reality</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00801.html">[MUD-Dev] Re: How to debug a method taking a variable list of arguments?</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00794"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00794"><STRONG>Thread</STRONG></A></LI>
</UL>
</LI>
</UL>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
<ul><li>Thread context:
<BLOCKQUOTE><UL>
<LI><STRONG>Re: [MUD-Dev] thoughts on game economies</STRONG>, <EM>(continued)</EM>
<ul compact>
<ul compact>
<ul compact>
<ul compact>
<ul compact>
<LI><strong><A NAME="00869" HREF="msg00869.html">Re: [MUD-Dev] thoughts on game economies</A></strong>, 
Greg Miller <a href="mailto:gmiller#classic-games,com">gmiller#classic-games,com</a>, Tue 22 Jun 1999, 00:26 GMT
<UL>
<LI><strong><A NAME="00870" HREF="msg00870.html">Re: [MUD-Dev] thoughts on game economies</A></strong>, 
Matthew Mihaly <a href="mailto:diablo#best,com">diablo#best,com</a>, Tue 22 Jun 1999, 01:24 GMT
</LI>
</UL>
</LI>
</ul>
</ul>
</ul>
</ul>
</ul>
</LI>
<LI><strong><A NAME="00803" HREF="msg00803.html">[MUD-Dev] ADMIN: Searching on MUD-Dev archives</A></strong>, 
claw <a href="mailto:claw#kanga,nu">claw#kanga,nu</a>, Mon 14 Jun 1999, 04:20 GMT
<LI><strong><A NAME="00802" HREF="msg00802.html">[MUD-Dev] Twisted Reality</A></strong>, 
claw <a href="mailto:claw#kanga,nu">claw#kanga,nu</a>, Mon 14 Jun 1999, 01:29 GMT
<LI><strong><A NAME="00794" HREF="msg00794.html">[MUD-Dev] How to debug a method taking a variable list of arguments?</A></strong>, 
Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Sun 13 Jun 1999, 07:01 GMT
<UL>
<LI><EM>Message not available</EM><UL>
<LI><strong><A NAME="00801" HREF="msg00801.html">[MUD-Dev] Re: How to debug a method taking a variable list of arguments?</A></strong>, 
Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Sun 13 Jun 1999, 21:24 GMT
</LI>
</UL>
</LI>
</UL>
<UL>
<li>&lt;Possible follow-up(s)&gt;<br>
<LI><strong><A NAME="00795" HREF="msg00795.html">Re: [MUD-Dev] How to debug a method taking a variable list of arguments?</A></strong>, 
Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Sun 13 Jun 1999, 17:02 GMT
</LI>
</UL>
</LI>
<LI><strong><A NAME="00783" HREF="msg00783.html">[MUD-Dev] Game economics</A></strong>, 
Matthew Mihaly <a href="mailto:diablo#best,com">diablo#best,com</a>, Sat 12 Jun 1999, 00:50 GMT
<UL>
<LI><strong><A NAME="00790" HREF="msg00790.html">Re: [MUD-Dev] Game economics</A></strong>, 
Nathan F Yospe <a href="mailto:yospe#hawaii,edu">yospe#hawaii,edu</a>, Sat 12 Jun 1999, 02:38 GMT
</LI>
</UL>
</LI>
</UL></BLOCKQUOTE>

</ul>
<hr>
<center>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
</center>
<hr>
</body>
</html>