1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

mrubyのメモリ使用状況を確認

Last updated at Posted at 2024-07-02

mruby on YABMではnewlibを使っていて、mallocの為に以下のような_sbrkを用意しています。

void *
_sbrk (incr)
     int incr;
{
   static char * heap_end = _end;
   char *        prev_heap_end;

   prev_heap_end = heap_end;
   heap_end += incr;

   return (void *) prev_heap_end;
}

mruby @ 7333713のadmbm(MIPS32)のmain.elfをobjdump -Dでheap_endを確認してみます。

800caa90 <heap_end.1855>:
800caa90:       800d9c40        lb      t5,-25536(zero)

初期値の_endはリンカースクリプトを元にldが値を入れてくれます。

malloc_heep.png

ここを見ればどれくらい使っているかわかります。

urjtagで見てみます。

jtag> cable UsbBlaster
Connected to libftd2xx driver.
jtag> detect
IR length: 5
Chain length: 1
Device Id: 00000000000000000000000000000001 (0x00000001)
  Unknown manufacturer! (00000000000) (/Users/hiroki/Develop/Device/OpenSrouce/urjtag-2018.09/urjtag/MANUFACTURERS)
jtag> include admtek/adm5120/adm5120
ImpCode=01000001010000000100000000000000 41404000
EJTAG version: 2.6
EJTAG Implementation flags: R4k DINTsup ASID_8 NoDMA MIPS32
Processor entered Debug Mode.
jtag> print
 No. Manufacturer              Part                 Stepping Instruction          Register                        
-------------------------------------------------------------------------------------------------------------------
   0                                                         EJTAG_DATA           EJDATA                          

Active bus:
*0: EJTAG compatible bus driver via PrAcc (JTAG part No. 0)
        start: 0x00000000, length: 0x20000000, data width: 8 bit
        start: 0x20000000, length: 0x20000000, data width: 16 bit
        start: 0x40000000, length: 0x20000000, data width: 32 bit
jtag> peek 0x400caa90
URJ_BUS_READ(0x400caa90) = 0x800E6000 (2148425728)

Processor entered Debug Modeでmrubyは止まります。

メモリは0x40000000で見えてるようなので、そのアドレスで見てみました。

hello.rbを実行して0xe6000-0xd9c40=50112バイトのようです。

OpenOCD

El CapitanのOpenOCD 0.10.0でも見てみます。

adm.cfg
set _CHIPNAME adm5120
set _CPUTAPID 0x00000001

jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id $_CPUTAPID

set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME mips_m4k -endian little -chain-position $_TARGETNAME

実行します。

$ src/openocd -f ft232h.cfg -f adm.cfg 
Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
adapter speed: 15000 kHz
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
adm5120.cpu
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
Info : clock speed 15000 kHz
Info : JTAG tap: adm5120.cpu tap/device found: 0x00000001 (mfg: 0x000 (<invalid>), part: 0x0000, ver: 0x0)

telnetしてみてみました。

Open On-Chip Debugger
> halt
target halted in MIPS32 mode due to debug-request, pc: 0x8009f3b4
> mdw 0x800caa90
0x800caa90: 800ed000 
> reg
===== mips32 registers
(0) r0 (/32): 0x00000000
(1) r1 (/32): 0x00800000
(2) r2 (/32): 0x00000001
(3) r3 (/32): 0x000007D0
(4) r4 (/32): 0x00000057
(5) r5 (/32): 0x800D9DB0
(6) r6 (/32): 0x000003E9
(7) r7 (/32): 0x00000000
(8) r8 (/32): 0x0000003F
(9) r9 (/32): 0x00000026
(10) r10 (/32): 0x0000007C
(11) r11 (/32): 0x0000002A
(12) r12 (/32): 0x0000003A
(13) r13 (/32): 0x00000021
(14) r14 (/32): 0x000000F5
(15) r15 (/32): 0x0000001C
(16) r16 (/32): 0x8009FCC8
(17) r17 (/32): 0xAB625776
(18) r18 (/32): 0xA8CA9596
(19) r19 (/32): 0x00000000
(20) r20 (/32): 0x00000000
(21) r21 (/32): 0x800E3840
(22) r22 (/32): 0x800D9DB0
(23) r23 (/32): 0x0000002F
(24) r24 (/32): 0x000000B2
(25) r25 (/32): 0x8009F360
(26) r26 (/32): 0x00000014
(27) r27 (/32): 0x807FFC50
(28) r28 (/32): 0x807F2D30
(29) r29 (/32): 0x807FFD78
(30) r30 (/32): 0x00000008
(31) r31 (/32): 0x8009F3BC
(32) status (/32): 0x00008001
(33) lo (/32): 0x0297C1E0
(34) hi (/32): 0x00000000
(35) badvaddr (/32): 0x8AE08183
(36) cause (/32): 0x90808000
(37) pc (/32): 0x8009F3B4
(38) f0 (/32): 0x00000000
(39) f1 (/32): 0x00000000
(40) f2 (/32): 0x00000000
(41) f3 (/32): 0x00000000
(42) f4 (/32): 0x00000000
(43) f5 (/32): 0x00000000
(44) f6 (/32): 0x00000000
(45) f7 (/32): 0x00000000
(46) f8 (/32): 0x00000000
(47) f9 (/32): 0x00000000
(48) f10 (/32): 0x00000000
(49) f11 (/32): 0x00000000
(50) f12 (/32): 0x00000000
(51) f13 (/32): 0x00000000
(52) f14 (/32): 0x00000000
(53) f15 (/32): 0x00000000
(54) f16 (/32): 0x00000000
(55) f17 (/32): 0x00000000
(56) f18 (/32): 0x00000000
(57) f19 (/32): 0x00000000
(58) f20 (/32): 0x00000000
(59) f21 (/32): 0x00000000
(60) f22 (/32): 0x00000000
(61) f23 (/32): 0x00000000
(62) f24 (/32): 0x00000000
(63) f25 (/32): 0x00000000
(64) f26 (/32): 0x00000000
(65) f27 (/32): 0x00000000
(66) f28 (/32): 0x00000000
(67) f29 (/32): 0x00000000
(68) f30 (/32): 0x00000000
(69) f31 (/32): 0x00000000
(70) fcsr (/32): 0x00000000
(71) fir (/32): 0x00000000
> resume

実行を継続できるので、任意のタイミングで何度でも確認できます。

MIPSが扱えるgdbがあればシンボルでも確認できますが、用意するのが大変です。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?