9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] 8l -e
@ 2014-05-27 20:10 Nick Owens
  2014-05-27 20:16 ` erik quanstrom
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Owens @ 2014-05-27 20:10 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 1711 bytes --]

i was trying to use 8l's '-e' flag today, when i found some
interesting problems.

first, -e doesn't do what it says unless you pass -p, which goes
unmentioned in the manual page. (luckily i read the source).

second, and more importantly, the calls to _tracein/_traceout are
skipped, as in the following disassembly, but i can't determine why. is
there some tool (besides noping with acid) meant to be used to 'turn on'
the tracing calls?

third, when you use -e with -p, prof.$pid files are generated as with
-p, but the prof files are empty. this seems unintentional.

this example is using rc.

; 8l -p -e -o 8.out code.8 exec.8 getflags.8 glob.8 here.8 io.8 lex.8
pcmd.8 pfnc.8 simple.8 subr.8 trap.8 tree.8 var.8 havefork.8 plan9.8
y.tab.8
; acid 8.out
8.out:386 plan 9 executable
/sys/lib/acid/port
/sys/lib/acid/386
acid: asm(setvar)
setvar 0x0000adbb   JMP	setvar+0x7(SB)
setvar+0x2 0x0000adbd	CALL	_tracein(SB)
setvar+0x7 0x0000adc2	SUBL	$0x10,SP
setvar+0xa 0x0000adc5	MOVL	name+0x0(FP),CX
setvar+0xe 0x0000adc9	MOVL	CX,0x0(SP)
setvar+0x11 0x0000adcc	CALL	vlook(SB)
setvar+0x16 0x0000add1	MOVL	AX,v+0xc(SP)
setvar+0x1a 0x0000add5	MOVL	0x4(AX),AX
setvar+0x1d 0x0000add8	MOVL	AX,0x0(SP)
setvar+0x20 0x0000addb	CALL	freewords(SB)
setvar+0x25 0x0000ade0	MOVL	v+0xc(SP),DX
setvar+0x29 0x0000ade4	MOVL	val+0x4(FP),CX
setvar+0x2d 0x0000ade8	MOVL	CX,0x4(DX)
setvar+0x30 0x0000adeb	MOVL	$0x1,0x8(DX)
setvar+0x37 0x0000adf2	ADDL	$0x10,SP
setvar+0x3a 0x0000adf5	RET
setvar+0x3b 0x0000adf6	CALL	_traceout(SB)
setvar+0x40 0x0000adfb	RET
Xasync 0x0000adfc   JMP	Xasync+0x7(SB)
acid: 

you can see there is a JMP over _tracein and a RET before _traceout.
what gives?


[-- Attachment #2: Type: application/pgp-signature, Size: 851 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] 8l -e
  2014-05-27 20:10 [9fans] 8l -e Nick Owens
@ 2014-05-27 20:16 ` erik quanstrom
  2014-05-27 21:30   ` Nick Owens
  0 siblings, 1 reply; 6+ messages in thread
From: erik quanstrom @ 2014-05-27 20:16 UTC (permalink / raw)
  To: 9fans

> you can see there is a JMP over _tracein and a RET before _traceout.
> what gives?

ah, that's the magic!  the idea is to be able to enable and disable these tracepoints
at runtime in a multiprocessor environment without any locking.

- erik



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] 8l -e
  2014-05-27 20:16 ` erik quanstrom
@ 2014-05-27 21:30   ` Nick Owens
  2014-05-27 21:33     ` erik quanstrom
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Owens @ 2014-05-27 21:30 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 1419 bytes --]

On Tue, May 27, 2014 at 04:16:24PM -0400, erik quanstrom wrote:
> > you can see there is a JMP over _tracein and a RET before _traceout.
> > what gives?
> 
> ah, that's the magic!  the idea is to be able to enable and disable these tracepoints
> at runtime in a multiprocessor environment without any locking.
> 
> - erik
> 

ok. i'm beginning to understand better. is there a specific use case,
such as the kernel or userland?

i didn't see anything like a tool that could poke nops into the right
places. i started to write an acid function to put the nops in one
 named function, and then i realized that the ret can appear several
 times in one function and i would need to search for and patch them
 out. but only the *first* ret, not second, e.g.:

 setvar+0x3a 0x0000adf5	RET			<--- should be NOP
 setvar+0x3b 0x0000adf6	CALL	_traceout(SB)
 setvar+0x40 0x0000adfb	RET			<--- should not be NOP

 i was able to patch the JMP, and the RET but only in the case where it
 appears at the bottom of a function.

defn traceon(fn){
	bound = fnbound(fn);

	// nop first jmp
	*(bound[0]) = 0x90\b;
	*(bound[0]+1) = 0x90\b;

	// and the ret
	// XXX should search for ret
	*(bound[1]-7) = 0x90\b;
}


maybe these were not the droids i was looking for.
my real goal is to make timing statistics for function calls in a program.
perhaps this goal is better fulfilled simply by prof!


[-- Attachment #2: Type: application/pgp-signature, Size: 851 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] 8l -e
  2014-05-27 21:30   ` Nick Owens
@ 2014-05-27 21:33     ` erik quanstrom
  2015-07-08  2:43       ` michaelian ennis
  0 siblings, 1 reply; 6+ messages in thread
From: erik quanstrom @ 2014-05-27 21:33 UTC (permalink / raw)
  To: 9fans

> ok. i'm beginning to understand better. is there a specific use case,
> such as the kernel or userland?
>
> i didn't see anything like a tool that could poke nops into the right
> places. i started to write an acid function to put the nops in one
>  named function, and then i realized that the ret can appear several
>  times in one function and i would need to search for and patch them
>  out. but only the *first* ret, not second, e.g.:

this tool was ment for use with the kernel.  there is a devtrace in 9atom's
pc and pcpae kernels that does this.

ron wrote a paper for the first athens, ga iwp9.  i don't remember the year.
2009?

- erik



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] 8l -e
  2014-05-27 21:33     ` erik quanstrom
@ 2015-07-08  2:43       ` michaelian ennis
  2015-07-08  2:44         ` michaelian ennis
  0 siblings, 1 reply; 6+ messages in thread
From: michaelian ennis @ 2015-07-08  2:43 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 30 bytes --]

4th iwp9
October 21-23 2009

[-- Attachment #2: Type: text/html, Size: 128 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] 8l -e
  2015-07-08  2:43       ` michaelian ennis
@ 2015-07-08  2:44         ` michaelian ennis
  0 siblings, 0 replies; 6+ messages in thread
From: michaelian ennis @ 2015-07-08  2:44 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 20 bytes --]

http://4e.iwp9.org

[-- Attachment #2: Type: text/html, Size: 148 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-07-08  2:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-27 20:10 [9fans] 8l -e Nick Owens
2014-05-27 20:16 ` erik quanstrom
2014-05-27 21:30   ` Nick Owens
2014-05-27 21:33     ` erik quanstrom
2015-07-08  2:43       ` michaelian ennis
2015-07-08  2:44         ` michaelian ennis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).