dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.27k stars 4.73k forks source link

[SOS][ARM/Linux] 'clru' sos command doesn't work #6384

Closed lucenticus closed 4 years ago

lucenticus commented 8 years ago

When I try to show annotated dissasembly by clru command on ARM/Linux, I get this result:

(lldb) clru 71CCB54A
Normal JIT generated code
HelloWorld3.Program.show_message()
Begin 71CCB510, size 78
(lldb) 

I investigated the code related with this command and I found that code of ARMMachine::Unassembly method is in #ifndef FEATURE_PAL (https://github.com/dotnet/coreclr/blob/master/src/ToolBox/SOS/Strike/disasmARM.cpp#L358). Is there any issues with this command on ARM/Linux? CC: @Dmitri-Botcharnikov @chunseoklee @mikem8361 @janvorli

mikem8361 commented 8 years ago

Someone that understands ARM disassembly needs to remove the ifdef and fix any problems. It hasn’t been ported to xplat yet (obviously). It should be much work because it works on windows.

lucenticus commented 8 years ago

It seems that this command works fine by removing #ifndef FEATURE_PAL, we just have to slightly change lldb code to enable armv7l

(lldb) clru 6FBA353E
Normal JIT generated code
HelloWorld3.Program.show_message()
Begin 6FBA3510, size 78

/media/epavlov/builds/Git/coreclr/Tools/helloworld3.cs @ 8:
000000006fba3510 2de9104c             .long   0x4c10e92d
000000006fba3514 84b00df1             .long   0xf10db084
000000006fba3518 180b0021             .long   0x21000b18
000000006fba351c 02910191             .long   0x91019102
000000006fba3520 00910390             andls   r9, r3, r0, lsl dotnet/coreclr#2
000000006fba3524 43f6e073             mvnvc   pc, #70254592
000000006fba3528 c7f2a653             .long   0x53a6f2c7
000000006fba352c 1b68002b             blhs    0x6fbbd5a0
000000006fba3530 04d047f6             .long   0xf647d004
000000006fba3534 8933c7f2             .long   0xf2c73389
000000006fba3538 5c639847             .long   0x4798635c
000000006fba353c 00bf42f2             vmax.f32 d27, d2, d0

/media/epavlov/builds/Git/coreclr/Tools/helloworld3.cs @ 9:
000000006fba3540 4033c7f2             .long   0xf2c73340
000000006fba3544 90331b68             ldmdavs r11, {r4, r7, r8, r9, r12, sp}
000000006fba3548 029342f2             vcgt.s8 d25, d2, d2

/media/epavlov/builds/Git/coreclr/Tools/helloworld3.cs @ 10:
000000006fba354c 4433c7f2             .long   0xf2c73344
000000006fba3550 90331b68             ldmdavs r11, {r4, r7, r8, r9, r12, sp}
000000006fba3554 019342f2             vcgt.s8 d25, d2, d1

/media/epavlov/builds/Git/coreclr/Tools/helloworld3.cs @ 11:
000000006fba3558 4833c7f2             .long   0xf2c73348
000000006fba355c 90331968             ldmdavs r9, {r4, r7, r8, r9, r12, sp}
000000006fba3560 0298019a             bls     0x6fc09570
000000006fba3564 45f2a173             .long   0x73a1f245
000000006fba3568 c7f28d23             orrhs   pc, sp, #1879048204
000000006fba356c 98470090             .long   0x90004798
000000006fba3570 00984cf2             vadd.i8 d25, d12, d0
000000006fba3574 8123c7f2             .long   0xf2c72381
000000006fba3578 a9139847             ldrmi   r1, [r8, r9, lsr dotnet/coreclr#7]
000000006fba357c 00bf00bf             svclt   #0xbf00

/media/epavlov/builds/Git/coreclr/Tools/helloworld3.cs @ 12:
000000006fba3580 04b0bde8             .long   0xe8bdb004
000000006fba3584 104c7047             .long   0x47704c10
(lldb) 

@mikem8361 Thanks!

mikem8361 commented 8 years ago

Are you going to create a PR with the changes?

lucenticus commented 8 years ago

There was an issue with clearing thumb bit, I've added commit which fixed this issue. Here is lldb output:

(lldb) clru 71CCB53E
Normal JIT generated code
HelloWorld3.Program.show_message()
Begin 71CCB510, size 78

/media/epavlov/builds/Git/coreclr/Tools/helloworld3.cs @ 8:
0000000071ccb510 2de9104c             push.w  {r4, r10, r11, lr}
0000000071ccb514 84b0                 sub     sp, #0x10
0000000071ccb516 0df1180b             add.w   r11, sp, #0x18
0000000071ccb51a 0021                 movs    r1, #0x0
0000000071ccb51c 0291                 str     r1, [sp, #0x8]
0000000071ccb51e 0191                 str     r1, [sp, #0x4]
0000000071ccb520 0091                 str     r1, [sp]
0000000071ccb522 0390                 str     r0, [sp, #0xc]
0000000071ccb524 43f6e073             movw    r3, #0x3fe0
0000000071ccb528 c7f2a653             movt    r3, #0x75a6
0000000071ccb52c 1b68                 ldr     r3, [r3]
0000000071ccb52e 002b                 cmp     r3, #0x0
0000000071ccb530 04d0                 beq     0x71ccb53c
0000000071ccb532 47f68933             movw    r3, #0x7b89
0000000071ccb536 c7f25c63             movt    r3, #0x765c (JitHelp: CORINFO_HELP_DBG_IS_JUST_MY_CODE)
0000000071ccb53a 9847                 blx     r3
0000000071ccb53c 00bf                 nop     

/media/epavlov/builds/Git/coreclr/Tools/helloworld3.cs @ 9:
>>> 0000000071ccb53e 42f24033             movw    r3, #0x2340
0000000071ccb542 c7f27033             movt    r3, #0x7370
0000000071ccb546 1b68                 ldr     r3, [r3]
0000000071ccb548 0293                 str     r3, [sp, #0x8]

/media/epavlov/builds/Git/coreclr/Tools/helloworld3.cs @ 10:
0000000071ccb54a 42f24433             movw    r3, #0x2344
0000000071ccb54e c7f27033             movt    r3, #0x7370
0000000071ccb552 1b68                 ldr     r3, [r3]
0000000071ccb554 0193                 str     r3, [sp, #0x4]

/media/epavlov/builds/Git/coreclr/Tools/helloworld3.cs @ 11:
0000000071ccb556 42f24833             movw    r3, #0x2348
0000000071ccb55a c7f27033             movt    r3, #0x7370
0000000071ccb55e 1968                 ldr     r1, [r3]
0000000071ccb560 0298                 ldr     r0, [sp, #0x8]
0000000071ccb562 019a                 ldr     r2, [sp, #0x4]
0000000071ccb564 45f2a173             movw    r3, #0x57a1
0000000071ccb568 c7f2ed13             movt    r3, #0x71ed (code for MD: System.String.Concat(System.String, System.String, System.String))
0000000071ccb56c 9847                 blx     r3
0000000071ccb56e 0090                 str     r0, [sp]
0000000071ccb570 0098                 ldr     r0, [sp]
0000000071ccb572 42f28123             movw    r3, #0x2281
0000000071ccb576 c7f2d013             movt    r3, #0x71d0 (code for MD: System.Console.WriteLine(System.String))
0000000071ccb57a 9847                 blx     r3
0000000071ccb57c 00bf                 nop     

/media/epavlov/builds/Git/coreclr/Tools/helloworld3.cs @ 12:
0000000071ccb57e 00bf                 nop     
0000000071ccb580 04b0                 add     sp, #0x10
0000000071ccb582 bde8104c             pop.w   {r4, r10, r11, lr}
0000000071ccb586 7047                 bx      lr
(lldb) 
Dmitri-Botcharnikov commented 8 years ago

LGTM