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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
170
スマートグラスで並列バイブコーディング
hyshu
0
210
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
270
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
260
Contextとはなにか
chiroruxx
1
340
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
13k
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
180
AIだと陥りがちなJakarta EE最新技術への移行時の落とし穴と解決策
tnagao7
0
110
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
150
Vite+ Unified Toolchain for the Web
naokihaba
0
320
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
11
5.9k
dRuby over BLE
makicamel
2
380
Featured
See All Featured
Navigating Team Friction
lara
192
16k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
How to Ace a Technical Interview
jacobian
281
24k
A better future with KSS
kneath
240
18k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.5k
Optimizing for Happiness
mojombo
378
71k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
The browser strikes back
jonoalderson
0
1.3k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.6k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
360
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
🦙