Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
LLDBを活用したデザインチェック
Search
Suita Fujino
June 23, 2021
Programming
2.5k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
LLDBを活用したデザインチェック
potatotips #74 (2021/6/23)
GitHub:
https://github.com/Scior/LLDBVisualDebug
Suita Fujino
June 23, 2021
Other Decks in Programming
See All in Programming
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
620
これって Effect でできたのでは? / TSKaigi Mashup Kansai #2
susisu
0
150
霧の中の代数的エフェクト
funnyycat
1
490
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
210
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
180
仕様駆動開発の消費期限
watany
17
7.3k
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
160
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
540
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
160
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
4.1k
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
120
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
450
Featured
See All Featured
Discover your Explorer Soul
emna__ayadi
2
1.2k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
230
The browser strikes back
jonoalderson
0
1.5k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
340
Color Theory Basics | Prateek | Gurzu
gurzu
0
410
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
310
Speed Design
sergeychernyshev
33
2k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
260
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.5k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
280
Transcript
(@Scior) LLDB Swift Python 1
AppBrew LIPS iOS PjM ( Keynote) ࣗݾհ🦙 ෩ܠ͖֯ͷਓू·Εʙ📷
None
(lldb) e view.isHidden = false
Google UI
Python
None
( )
UIView Save
UIView UIView Data UIGraphicsImageRenderer SBProcess.ReadMemory Lib/io LLDB
(lldb) saveimage imageView /tmp/alpaca.png
Swift ( ) loadext DebugExtensions.swift evaluate DebugExtensions.swift
Swift (loadext) @lldb.command("loadext") def load(debugger, command, result, dict): path =
os.path.join(os.path.dirname(__file__), 'swift/DebugExtensions.swift') with open(path, 'r') as f: common.evaluate(f.read()) * common.evaluate
DebugExtensions.swift extension UIView { func takeSnapshot() -> UIImage? { let
renderer = UIGraphicsImageRenderer(bounds: bounds) return renderer.image { context in layer.render(in: context.cgContext) } } func convertToPNGData() -> Data { return takeSnapshot()!.pngData()! } } ͪΖΜ#if DEBUG ~ #endifͰғͬͯίϯύΠϧͯ͠ྑ͍
saveimage ( ) saveimage convertToPNGData() evaluate convertToPNGData() DebugExtensions.swift
saveimage ( ) saveimage address size convertToPNGData() evaluate convertToPNGData() Data
SBValue DebugExtensions.swift
saveimage ( ) @lldb.command("saveimage") def save_image(debugger, arguments, result, dict): view,
path = arguments.split() var_name = str(uuid.uuid4()).replace('-', '') common.evaluate('let $%s = %s.convertToPNGData()' % (var_name, view)) address_str = common.evaluate('($%s as NSData).bytes' % var_name).GetObjectDescription().split()[1] address = int(address_str, 16) size = int(common.evaluate('$%s.count' % var_name).GetValue()) process = lldb.debugger.GetSelectedTarget().GetProcess() error = lldb.SBError() data = process.ReadMemory(address, size, error) with open(path, "wb") as f: f.write(data)
@lldb.command("saveimage") def save_image(debugger, arguments, result, dict): @lldb.command command script add
-f LLDB
convertToPNGData() common.evaluate('let $%s = %s.convertToPNGData()' % (var_name, view)) let $hoge
= imageView.convertToPNGData()
Data address_str = common.evaluate('($%s as NSData).bytes' % var_name).GetObjectDescription().split()[1] address =
int(address_str, 16) size = int(common.evaluate('$%s.count' % var_name).GetValue()) ($hoge as NSData).bytes $hoge.count (Obj-C++ )
process = lldb.debugger.GetSelectedTarget().GetProcess() error = lldb.SBError() data = process.ReadMemory(address, size,
error) with open(path, "wb") as f: f.write(data) SBProcess.ReadMemory Python
* GitHub
( )
UIView Overlay
UIView Data UIImage UnsafeMutablePointer UIImage.init(data:) Lib/io SBProcess.WriteMemory LLDB
(lldb) overlayimage imageView /tmp/alpaca.png
ImageBuffer final class ImageBuffer { typealias Pointer = UnsafeMutablePointer<UInt8> private
let size: Int let pointer: Pointer init(size: Int) { self.size = size pointer = Pointer.allocate(capacity: size) } deinit { pointer.deallocate() } func getData() -> Data { let bufferPointer = UnsafeMutableBufferPointer(start: pointer, count: size) return .init(buffer: bufferPointer) } }
overlayimage @lldb.command("overlayimage") def overlay_image(debugger, arguments, result, dict): view, path =
arguments.split() with open(path, 'rb') as f: data = f.read() buf_name = common.generateVarName() common.evaluate('let $%s = ImageBuffer(size: %s)' % (buf_name, len(data))) address_str = common.evaluate('$%s.pointer' % buf_name).GetObjectDescription().split()[1] address = int(address_str, 16) process = lldb.debugger.GetSelectedTarget().GetProcess() error = lldb.SBError() size = process.WriteMemory(address, data, error) view_name = common.generateVarName() common.evaluate('let $%s = DebugOverlayView(frame: %s.frame)' % (view_name, view)) common.evaluate('$%s.set(data: $%s.getData())' % (view_name, buf_name)) common.evaluate(‘%s.superview?.addSubview($%s)' % (view, view_name))
with open(path, 'rb') as f: data = f.read() common.evaluate('let $%s
= ImageBuffer(size: %s)' % (buf_name, len(data))) address_str = common.evaluate('$%s.pointer' % buf_name).GetObjectDescription().split()[1] address = int(address_str, 16) ImageBuffer
process = lldb.debugger.GetSelectedTarget().GetProcess() error = lldb.SBError() size = process.WriteMemory(address, data,
error) SBProcess.WriteMemory
View common.evaluate('let $%s = DebugOverlayView(frame: %s.frame)' % (view_name, view)) common.evaluate('$%s.set(data:
$%s.getData())' % (view_name, buf_name)) common.evaluate(‘%s.superview?.addSubview($%s)' % (view, view_name)) let $view = DebugOverlayView(frame: view.frame) $view.set(data: $buf.getData()) view.superview?.addSubview($view)
☺ * GitHub
With OpenCV and scikit-image (in progress) View cv skimage (UILabel
)
https://github.com/Scior/LLDBVisualDebug
Appendix
common.evaluate def evaluate(exp): options = lldb.SBExpressionOptions() options.SetLanguage(lldb.eLanguageTypeSwift) frame = (
lldb.debugger.GetSelectedTarget() .GetProcess() .GetSelectedThread() .GetSelectedFrame() ) return frame.EvaluateExpression(exp, options)
LLDB Python API: https://lldb.llvm.org/python_api.html facebook/chisel: https://github.com/facebook/chisel
🦙