* [9fans] An acid-question
@ 2006-07-15 10:55 Sascha Retzki
2006-07-15 11:22 ` erik quanstrom
0 siblings, 1 reply; 8+ messages in thread
From: Sascha Retzki @ 2006-07-15 10:55 UTC (permalink / raw)
To: 9fans
Hi folks,
I got a function which goes like this:
void
m00(...)
{
int i,j = 0;
if(foo) {
for(i=0;i<=n;i++) {
some_data[j++] = srcdata[i]
}
} else {
...
}
}
(ignore the errors)
I get a fault write. Jippie. Starting to acid arround, I came across this:
acid: *m00:j
0x00000000
acid: *m00:i
<stdin>:3: (error) colon: local variable not found
acid:
so obviously acid does not 'see' i because it is first used in a new block (the if()), at least I guess so. How do I display the value of i in acid?
Mfg, Sascha
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9fans] An acid-question
2006-07-15 10:55 [9fans] An acid-question Sascha Retzki
@ 2006-07-15 11:22 ` erik quanstrom
2006-07-15 15:28 ` Sascha Retzki
0 siblings, 1 reply; 8+ messages in thread
From: erik quanstrom @ 2006-07-15 11:22 UTC (permalink / raw)
To: 9fans
i doesn't exist -- it was optimized away because your code is equivalent to this
void
m00(...)
{
int i;
if(foo){
for(i = 0; i <= n; i++){
some_data[i] = srcdata[i]
}
} else {
...
}
}
because i == j.
- erik
On Sat Jul 15 05:55:56 CDT 2006, sretzki@gmx.de wrote:
>
> Hi folks,
>
> I got a function which goes like this:
> void
> m00(...)
> {
> int i,j = 0;
>
> if(foo) {
>
> for(i=0;i<=n;i++) {
> some_data[j++] = srcdata[i]
> }
>
> } else {
> ...
> }
> }
>
> (ignore the errors)
>
> I get a fault write. Jippie. Starting to acid arround, I came across this:
>
> acid: *m00:j
> 0x00000000
> acid: *m00:i
> <stdin>:3: (error) colon: local variable not found
> acid:
>
> so obviously acid does not 'see' i because it is first used in a new block (the if()), at least I guess so. How do I display the value of i in acid?
>
>
> Mfg, Sascha
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9fans] An acid-question
2006-07-15 15:28 ` Sascha Retzki
@ 2006-07-15 12:15 ` erik quanstrom
2006-07-15 12:36 ` Sascha Retzki
0 siblings, 1 reply; 8+ messages in thread
From: erik quanstrom @ 2006-07-15 12:15 UTC (permalink / raw)
To: 9fans
your loop test has an obiwan error:
for(i=0;i <= inbyterate;i++) {
should be
for(i = 0; i < inbyterate; i++);
- erik
On Sat Jul 15 06:42:57 CDT 2006, sretzki@gmx.de wrote:
> Okay, I will never write pseudo-like code to demonstrate what I mean :/
>
> fmt is a structure holding all meta-data of the audio-input. convertchannels() is called by a function which reads fmt->byterate audio-data from stdin, and provides another array big enough to hold a copy of the input-data (datacopy).
>
> void
> convertchannels(short *data, short *datacopy)
> {
> int i, j = 0;
> int inbyterate = fmt->samplerate * fmt->channels * 2;
>
>
> memcpy(datacopy,data,inbyterate * sizeof(short));
>
>
> if(fmt->channels == 1) {
>
> for(i=0;i <= inbyterate;i++) {
>
> /* mono to left ... */
> data[j++] = datacopy[i];
>
> /* mono to right ... */
> data[j++] = datacopy[i];
>
> }
> }
> else
> sysfatal("convertchannels(): I can just convert from mono to stereo :-/\n");
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9fans] An acid-question
2006-07-15 12:15 ` erik quanstrom
@ 2006-07-15 12:36 ` Sascha Retzki
2006-07-15 12:39 ` erik quanstrom
2006-07-15 17:02 ` jmk
0 siblings, 2 replies; 8+ messages in thread
From: Sascha Retzki @ 2006-07-15 12:36 UTC (permalink / raw)
To: 9fans
> your loop test has an obiwan error:
>
> for(i=0;i <= inbyterate;i++) {
>
> should be
> for(i = 0; i < inbyterate; i++);
>
heh.. 'oups' ;) .. Thanks Erik. Nevertheless, that is not the problem. Do you have an idea why acid does not 'see' i ? Or how I can investigate i?
> - erik
>
> On Sat Jul 15 06:42:57 CDT 2006, sretzki@gmx.de wrote:
>> Okay, I will never write pseudo-like code to demonstrate what I mean :/
>>
>> fmt is a structure holding all meta-data of the audio-input. convertchannels() is called by a function which reads fmt->byterate audio-data from stdin, and provides another array big enough to hold a copy of the input-data (datacopy).
>>
>> void
>> convertchannels(short *data, short *datacopy)
>> {
>> int i, j = 0;
>> int inbyterate = fmt->samplerate * fmt->channels * 2;
>>
>>
>> memcpy(datacopy,data,inbyterate * sizeof(short));
>>
>>
>> if(fmt->channels == 1) {
>>
>> for(i=0;i <= inbyterate;i++) {
>>
>> /* mono to left ... */
>> data[j++] = datacopy[i];
>>
>> /* mono to right ... */
>> data[j++] = datacopy[i];
>>
>> }
>> }
>> else
>> sysfatal("convertchannels(): I can just convert from mono to stereo :-/\n");
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9fans] An acid-question
2006-07-15 12:36 ` Sascha Retzki
@ 2006-07-15 12:39 ` erik quanstrom
2006-07-15 17:02 ` jmk
1 sibling, 0 replies; 8+ messages in thread
From: erik quanstrom @ 2006-07-15 12:39 UTC (permalink / raw)
To: 9fans
On Sat Jul 15 07:37:29 CDT 2006, sretzki@gmx.de wrote:
> > your loop test has an obiwan error:
> >
> > for(i=0;i <= inbyterate;i++) {
> >
> > should be
> > for(i = 0; i < inbyterate; i++);
> >
>
> heh.. 'oups' ;) .. Thanks Erik. Nevertheless, that is not the problem. Do you have an idea why acid does not 'see' i ? Or how I can investigate i?
i = j/2. i'm still pretty sure that kenc is optimizing i away. here's what i'd
do. if samplerate is large (~10000), you need to make sure that data and datacopy
are not on the stack. then run acid on the broken process and make sure you're
actually on the line expected and use i = j/2 to figure out what i is.
- erik
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9fans] An acid-question
2006-07-15 11:22 ` erik quanstrom
@ 2006-07-15 15:28 ` Sascha Retzki
2006-07-15 12:15 ` erik quanstrom
0 siblings, 1 reply; 8+ messages in thread
From: Sascha Retzki @ 2006-07-15 15:28 UTC (permalink / raw)
To: 9fans
> i doesn't exist -- it was optimized away because your code is equivalent to this
>
Okay, I will never write pseudo-like code to demonstrate what I mean :/
fmt is a structure holding all meta-data of the audio-input. convertchannels() is called by a function which reads fmt->byterate audio-data from stdin, and provides another array big enough to hold a copy of the input-data (datacopy).
void
convertchannels(short *data, short *datacopy)
{
int i, j = 0;
int inbyterate = fmt->samplerate * fmt->channels * 2;
memcpy(datacopy,data,inbyterate * sizeof(short));
if(fmt->channels == 1) {
for(i=0;i <= inbyterate;i++) {
/* mono to left ... */
data[j++] = datacopy[i];
/* mono to right ... */
data[j++] = datacopy[i];
}
}
else
sysfatal("convertchannels(): I can just convert from mono to stereo :-/\n");
>
> - erik
>
> On Sat Jul 15 05:55:56 CDT 2006, sretzki@gmx.de wrote:
>>
>> Hi folks,
>>
>> I got a function which goes like this:
>> void
>> m00(...)
>> {
>> int i,j = 0;
>>
>> if(foo) {
>>
>> for(i=0;i<=n;i++) {
>> some_data[j++] = srcdata[i]
>> }
>>
>> } else {
>> ...
>> }
>> }
>>
>> (ignore the errors)
>>
>> I get a fault write. Jippie. Starting to acid arround, I came across this:
>>
>> acid: *m00:j
>> 0x00000000
>> acid: *m00:i
>> <stdin>:3: (error) colon: local variable not found
>> acid:
>>
>> so obviously acid does not 'see' i because it is first used in a new block (the if()), at least I guess so. How do I display the value of i in acid?
>>
>>
>> Mfg, Sascha
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9fans] An acid-question
2006-07-15 12:36 ` Sascha Retzki
2006-07-15 12:39 ` erik quanstrom
@ 2006-07-15 17:02 ` jmk
2006-07-15 17:09 ` Sascha Retzki
1 sibling, 1 reply; 8+ messages in thread
From: jmk @ 2006-07-15 17:02 UTC (permalink / raw)
To: 9fans
On Sat Jul 15 08:37:19 EDT 2006, sretzki@gmx.de wrote:
> ...
> Thanks Erik. Nevertheless, that is not the problem.
> Do you have an idea why acid does not 'see' i ? Or how
> I can investigate i?
Erik is right that 'i' is optimised. It's not optimised away,
but it does not appear in the symbol table because its entire
use lifetime it is held in a register; acid therefore can't
find it.
Assuming this code was in file a.c, after you have done
8c -FTVw a.c
then
nm -a a.8
will show a line for 'j':
8 a j
indicating it is an automatic variable, but there is no
output for 'i'. If you look at the code with acid (e.g.
'asm(convertchannels)' followed by 'casm()' until you get
to the code you are interested in you will see something
like this:
ethel% acid 8.out
8.out:386 plan 9 executable
/sys/lib/acid/port
/sys/lib/acid/386
lib/acid
acid: asm(convertchannels)
convertchannels 0x00001020 SUBL $0x20,SP
convertchannels+0x3 0x00001023 MOVL fmt(SB),BX
convertchannels+0x9 0x00001029 MOVL $0x0,j+0x18(SP)
convertchannels+0x11 0x00001031 MOVL 0x0(BX),AX
convertchannels+0x13 0x00001033 MOVL 0x4(BX),CX
convertchannels+0x16 0x00001036 IMULL AX,CX
convertchannels+0x18 0x00001038 ADDL AX,AX
convertchannels+0x1a 0x0000103a MOVL AX,CX
convertchannels+0x1c 0x0000103c MOVL datacopy+0x4(FP),AX
convertchannels+0x20 0x00001040 MOVL AX,0x0(SP)
convertchannels+0x23 0x00001043 MOVL data+0x0(FP),AX
convertchannels+0x27 0x00001047 MOVL AX,0x4(SP)
convertchannels+0x2b 0x0000104b MOVL CX,AX
convertchannels+0x2d 0x0000104d MOVL CX,inbyterate+0x14(SP)
convertchannels+0x31 0x00001051 ADDL AX,AX
convertchannels+0x33 0x00001053 MOVL AX,0x8(SP)
convertchannels+0x37 0x00001057 CALL memcpy(SB)
convertchannels+0x3c 0x0000105c MOVL data+0x0(FP),DI
convertchannels+0x40 0x00001060 MOVL j+0x18(SP),SI
convertchannels+0x44 0x00001064 MOVL fmt(SB),AX
convertchannels+0x4a 0x0000106a MOVL 0x4(AX),AX
convertchannels+0x4d 0x0000106d CMPL AX,$0x1
convertchannels+0x50 0x00001070 JNE convertchannels+0x87(SB)
convertchannels+0x52 0x00001072 XORL BP,BP
convertchannels+0x54 0x00001074 CMPL inbyterate+0x14(SP),BP
convertchannels+0x58 0x00001078 JGT convertchannels+0x83(SB)
convertchannels+0x5a 0x0000107a MOVL SI,AX
convertchannels+0x5c 0x0000107c INCL SI
convertchannels+0x5d 0x0000107d LEAL 0x0(DI)(AX*2),AX
convertchannels+0x60 0x00001080 MOVL datacopy+0x4(FP),BX
acid: casm()
convertchannels+0x64 0x00001084 MOVWSX 0x0(BX)(BP*2),CX
convertchannels+0x68 0x00001088 MOVW CX,0x0(AX)
convertchannels+0x6b 0x0000108b MOVL SI,AX
convertchannels+0x6d 0x0000108d INCL SI
convertchannels+0x6e 0x0000108e LEAL 0x0(DI)(AX*2),AX
convertchannels+0x71 0x00001091 MOVL datacopy+0x4(FP),BX
convertchannels+0x75 0x00001095 MOVWSX 0x0(BX)(BP*2),CX
convertchannels+0x79 0x00001099 MOVW CX,0x0(AX)
convertchannels+0x7c 0x0000109c INCL BP
convertchannels+0x7d 0x0000109d CMPL inbyterate+0x14(SP),BP
convertchannels+0x81 0x000010a1 JLE convertchannels+0x5a(SB)
convertchannels+0x83 0x000010a3 ADDL $0x20,SP
convertchannels+0x86 0x000010a6 RET
convertchannels+0x87 0x000010a7 MOVL $.string(SB),AX
convertchannels+0x8c 0x000010ac MOVL AX,0x0(SP)
convertchannels+0x8f 0x000010af CALL sysfatal(SB)
convertchannels+0x94 0x000010b4 JMP convertchannels+0x83(SB)
acid:
ethel%
The loop using 'i' starts at convertchannels+0x52
and 'i is held in register BP. You can use the 'regs()'
or 'gpr()' commands to examine BP in a broken proc.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9fans] An acid-question
2006-07-15 17:02 ` jmk
@ 2006-07-15 17:09 ` Sascha Retzki
0 siblings, 0 replies; 8+ messages in thread
From: Sascha Retzki @ 2006-07-15 17:09 UTC (permalink / raw)
To: 9fans
> If you look at the code with acid (e.g.
> 'asm(convertchannels)' followed by 'casm()' until you get
> to the code you are interested in you will see something
> like this:
Nice to know, thanks.
Sascha
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2006-07-15 17:09 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-15 10:55 [9fans] An acid-question Sascha Retzki
2006-07-15 11:22 ` erik quanstrom
2006-07-15 15:28 ` Sascha Retzki
2006-07-15 12:15 ` erik quanstrom
2006-07-15 12:36 ` Sascha Retzki
2006-07-15 12:39 ` erik quanstrom
2006-07-15 17:02 ` jmk
2006-07-15 17:09 ` Sascha Retzki
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).