Sign in to follow this  
nuclear123

is this possible...?

Recommended Posts

[code]int function(...)
{
int x;
int q;


if (condition)
{
}

<-----is there a way to put a marker here...then use a pointer to store the address of the marker...right before the 2nd conditional statement in my code?

if (condition2)
{

}


return val;
}
[/code]

Share this post


Link to post
Share on other sites
[code]int function(...)
{
int x;
int q;


if (condition)
{
}

return function2(x, q);
}

int function2(...)
{
if (condition2)
{

}


return val;
}
[/code]


You could just do something like that. It's hard to tell without some real code >.<

Share this post


Link to post
Share on other sites
What are you trying to do? If you want to jump to a specific part of the code, that is generally frowned on. It makes for very unreadable and unmaintainable code. If you are just trying to debug, just put a statement there such as a printf().

Share this post


Link to post
Share on other sites
im trying to use the address,hardcoded at compile time, to read in the bytes starting at that address till the end of the return and store all these bytes into a buffer..... -thx

Share this post


Link to post
Share on other sites
[quote name='nuclear123' timestamp='1298342042' post='4777347']
im trying to use the address,hardcoded at compile time, to read in the bytes starting at that address till the end of the return and store all these bytes into a buffer..... -thx
[/quote]

>.< But why? You could use a function pointer address and try and increment it by some value I guess. But what are you trying to accomplish?

Share this post


Link to post
Share on other sites
So are you trying to have the program read a portion of itself? If so, why?

edit: Also, if I understand correctly, I think you will be reading the actual compiled x86 instructions. That is, if you're looking to get variable values, those will be stored elsewhere, in the stack or heap.

Share this post


Link to post
Share on other sites
When you say "all these bytes" what bytes are you referring to? Some section of compiled machine code? I agree with others that the better question is what problem are you attempting to solve with this so you can be given a better solution.

Share this post


Link to post
Share on other sites
im wanting to read my compiled code at a certain point(which i specify) read it into a buffer, and then be able to copy those bytes to a file for viewing...!

Share this post


Link to post
Share on other sites
[quote name='nuclear123' timestamp='1298343078' post='4777353']
im wanting to read my compiled code at a certain point(which i specify) read it into a buffer, and then be able to copy those bytes to a file for viewing...!
[/quote]
That is a more detailed 'what' but you still haven't given a 'why'. If you want to see the 'machine code' just tell your compiler to generate assembly.

Share this post


Link to post
Share on other sites
[quote name='nobodynews' timestamp='1298344296' post='4777359']
[quote name='nuclear123' timestamp='1298343078' post='4777353']
im wanting to read my compiled code at a certain point(which i specify) read it into a buffer, and then be able to copy those bytes to a file for viewing...!
[/quote]
That is a more detailed 'what' but you still haven't given a 'why'. If you want to see the 'machine code' just tell your compiler to generate assembly.
[/quote]

Why does it matter WHY he wants this? it's none of your business, he's just asking if it can be done.

It CAN be done, and there are multiple ways of doing it. Without getting into assembly, you could use the function pointer idea (assign a function to a function pointer, which will then point to that funciton's location in memory), but it would have to be offset by some value to get somewhere in the middle of the function. i don't know how to do that without assembly.

With assembly, you would add an assembly section to basically perform a jump and link at the end of the seciton, and be sure and store the return address in a register, and copy it to a variable (I don't know x86 way of doing it). In MIPS, it would be something like this:
[code]
void *pvLocation;

if (cond)
{
}
asm {
// store old $ra in $t0
add $to, $ra, $0
b Step1
nop
Step2:
// Address at End is now stored in $ra register, copy it to our variable
// but add 4 1st point at end of instruction at End:
addi $ra, $ra, 4
sw $ra, pvLocation
b End
nop
Step1:
jal Step2
nop
End:
add $ra, $t0, $0
}

// now pvLocation store address of right here
[/code]

Yes, it's a bit of a hack, but, it is possible. You'll probably want to do this via x86 instructions though.

Share this post


Link to post
Share on other sites
[quote name='BeerNutts' timestamp='1298399722' post='4777620']
Why does it matter WHY he wants this? it's none of your business, he's just asking if it can be done.[/quote]

It IS important why because this is a game development forum for beginners. This is neither a game development related topic NOR a beginner's topic. Since the OP is POSTING in the beginner's forum, people want to know what he's trying to accomplish in case he's going about it the completely wrong way. He could have very well posted this in General Programming and most likely wouldn't have been pounded with people asking him why he wants to do this. I don't see why people like to be so damn secretive.

Share this post


Link to post
Share on other sites
[quote name='BeerNutts' timestamp='1298399722' post='4777620']
Why does it matter WHY he wants this? it's none of your business, he's just asking if it can be done.[/quote]
Because if he wants to see the machine code he could just tell his compiler to generate assembly meaning he won't need to do some hack to get data he would have to convert back to assembly to even understand. People overcomplicate things all the time. I can't count the number of times where I've got my mind set on going about something a certain way only to eventually realize I could have solved it another, simpler way. Basically, some questions being asked may be making assumptions that should be questioned from time to time and this is particularly true of For Beginners.

Share this post


Link to post
Share on other sites
[quote name='BeerNutts' timestamp='1298399722' post='4777620']Why does it matter WHY he wants this? it's none of your business, he's just asking if it can be done.[/quote]
It matters why because he's obviously trying to solve some kind of problem, and he's focussing more on how he wants to solve it rather than on what he wants to solve. The solution he's chosen may not be the best one, or may not even be appropriate for solving his problem. "This is what I want to achieve, how do I do it?" is a better line of inquiry than "this is the solution I've chosen to solve some undefined problem, will it work?"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this