Page 1 of 1

Is that possible to disasemble a procedure (a bug?) ?

Posted: Fri Apr 29, 2016 10:17 am
by Mesa
I try to disasemble a procedure, but i've got a problem (a bug ?)

Code: Select all

DisableDebugger 


  Procedure ranasm()
  aaaa:
    
  a = (Random(100) * 5) + 2000
  ProcedureReturn a
  
  zzzz:
EndProcedure

MessageRequester("Result", Str(ranasm())) 

bbbb:
a = (Random(100) * 5) + 2000
cccc:

  Texte$ = "Code disasembled: " + Chr(13)  
  If ExamineAssembly(?l_ranasm_aaaa, ?l_ranasm_zzzz) ; doesn't work
  ;If ExamineAssembly(?bbbb, ?cccc) ; it works out a procedure
    While NextInstruction()
      Texte$ + RSet(Hex(InstructionAddress()), SizeOf(Integer)*2, "0")
      Texte$ + " " + InstructionString() + Chr(13)
    Wend
  EndIf
  
  MessageRequester("Result", Texte$)

M.

Re: Is that possible to disasemble a procedure (a bug?) ?

Posted: Fri Apr 29, 2016 10:50 am
by Keya
labels are local to a procedure so you can't access them globally, there's a current thread about it here.
Regarding the topic ("possible to disassemble a procedure?"), you can simply by getting the address of the procedure itself instead of a label:

Code: Select all

Procedure Test()
EndProcedure

Debug "Address=0x" + Hex( @Test() )

Re: Is that possible to disasemble a procedure (a bug?) ?

Posted: Fri Apr 29, 2016 12:18 pm
by DontTalkToMe
How could referencing l_ranasm_aaaa work ?
Do you see a Basic label l_ranasm_aaaa somewhere ?
There may be a asm label in the generated code (actually with two "l'), but not something you can reference through PB commands.

This may give you an idea about how disassemble the whole procedure, if that's acceptable.

http://www.purebasic.fr/english/viewtop ... 77#p483177

That is supposing PB procs have a single exit point. I think they have (?)

Re: Is that possible to disasemble a procedure (a bug?) ?

Posted: Mon May 02, 2016 2:37 pm
by Mesa
@DontTalkToMe :
Do you see a Basic label l_ranasm_aaaa somewhere ?
In the doc, here: https://www.purebasic.com/documentation ... edasm.html

we can read:
- When you reference a label, you must put the prefix 'll_' before the name. This is because PureBasic add a 'll_' before a BASIC label to avoid conflict with internal labels. The label need to be referenced in lowercase when using the in-line ASM. If the label is defined in a procedure, then its prefix is 'l_procedurename_', in lowercase.
Do you see the "l_ranasm_aaaa" now ? :P

I think the doc has to be more explicit about that.

M.

Re: Is that possible to disasemble a procedure (a bug?) ?

Posted: Mon May 02, 2016 3:01 pm
by DontTalkToMe
Mesa wrote: Do you see the "l_ranasm_aaaa" now ? :P
No, I don't. :)
myself wrote: Do you see a Basic label l_ranasm_aaaa somewhere ?
There may be a asm label in the generated code (actually with two "l'), but not something you can reference through PB commands.
There is no l_ranasm_aaaa: BASIC label, there is a aaaa: BASIC label, local to the procedure.

The section of the manual you are citing says the same thing I tried to explain above. It's talking about how BASIC labels are renamed when converted to ASM labels, accessible through inline ASM.
And it's already explicit about that.
In your code you are passing to a BASIC command labels (incidentally not existing anyway) meant to be accessed through inline ASM.
That's all.

The help on the other hand is wrong about the "l" and "ll" but it's irrelevant in this specific case, your code wouldn't work even using the right label ll_ranasm_aaaa: