Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7588917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:02:50+00:00 2026-05-30T20:02:50+00:00

I am implementing a backtrace function in C, which can output caller’s info. like

  • 0

I am implementing a backtrace function in C, which can output caller’s info. like this

ebp:0x00007b28 eip:0x00100869 args:0x00000000 0x00640000 0x00007b58 0x00100082

But how can I know the count of arguments of the caller?

Thank you very much

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:02:52+00:00Added an answer on May 30, 2026 at 8:02 pm

    You can deduce the numbers of arguments a function uses in 32bit x86 code under some circumstances.
    If the code has been compiled to use framepointers, then a given function’s stackframe extends between (highest address) EBP and (lowest address / stack top) ESP. Immediately above the stack end at EBP you find the return address, and again above that you’ll have, if your code is using the C calling convention (cdecl), consecutively, arg[0...].

    That means: arg[0] at [EBP + 4], arg[1] at [EBP + 8 ], and so on.

    When you disassemble function, look for instructions referencing [EBP + ...] and you know they access function arguments. The highest offset value used tells you how many there are.

    This is of course somewhat simplified; arguments with sizes different from 32bits, code that doesn’t use cdecl but e.g. fastcall, code where the framepointer has been optimized makes the method trip, at least partially.

    Another option, again for cdecl functions, is to look at the return address (location of the call into the func you’re interested in), and disassemble around there; you will, in many cases, find a sequence push argN; push ...; push arg0; call yourFunc and you can deduce how many arguments were passed in this instance. That’s in fact the only way (from the code alone) to test how many arguments were passed to functions like printf() in a particular instance.
    Again, not perfect – these days, compilers often preallocate stackspace and then use mov to write arguments instead of pushing them (on some CPUs, this is better since sequences of push instructions have dependencies on each other due to each modifying the stackpointers).

    Since all these methods are heuristic this requires quite a bit of coding to automate. If compiler-generated debugging information is available, use that – it’s faster.

    Edit: There’s another useful heuristic that can be done; Compiler-generated code for function calling often looks like this:

    ...
    [ code that either does "push arg" or "mov [ESP ...], arg" ]
    ...
    call function
    add  ESP, ...
    

    The add instruction is there to clean up stackspace used for arguments. From the size of the immediate operand, you know how much space the args this code gave to function has used, and by implication (assuming they’re all 32bit, for example), you know how many there were.
    This is particularly simple given you already have the address of said add instruction if you have working backtrace code – the instruction at the return address is this add. So you can often get away with simply trying to disassemble the (single) instruction at the return address, and see if it’s an add ESP, ... (sometimes it’s a sub ESP, -...) and if so, calculate the number of arguments passed from the immediate operand. The code for that is much simpler than having to pull in a full disassembly library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When implementing move constructors and move assignment operators, one often writes code like this:
implementing publishActivity in PHP using the REST API using this code: $activity = array(
implementing service something similar with tinyurl or bit.ly, I'm would like to expose service
When implementing HTTP services in node.js, there is a lot of sample code like
When implementing a Matrix construct using arrays, which would be more efficient? Using a
When implementing a MessageFactory class to instatiate Message objects I used something like: class
Im implementing NFS and almoste done but the RFC section 3.3.8 says this in
Implementing/handling idempotency in c# with Jolivers EventStore. Does this mean just taking care of
Implementing ArrayAccess Interface in PHP , We can access Object Properties as Array Keys
While implementing the code from this question on my project I realized there's 3

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.