Upgrade to Pro — share decks privately, control downloads, hide ads and more …

LLDB の世界からみた Swift

LLDB の世界からみた Swift

AKIBA.swift×Swift愛好会

Toshihiro Morimoto

August 29, 2016
Tweet

More Decks by Toshihiro Morimoto

Other Decks in Technology

Transcript

  1. • iOS Application, Playground, etc.. • Server Side Swift •

    Swift Compiler • Swift Interpliter Language (SIL) • LLDB
  2. • iOS Application, Playground, etc.. • Server Side Swift •

    Swift Compiler • Swift Interpliter Language (SIL) • LLDB
  3. ࣮ߦ͢Δ (lldb) p “AKIBA.swift×SwiftѪ޷ձ” (String) $R1 = “AKIBA.swift×SwiftѪ޷ձ" (lldb) po

    “AKIBA.swift×SwiftѪ޷ձ” “AKIBA.swift×SwiftѪ޷ձ” (lldb) po $R1 “AKIBA.swift×SwiftѪ޷ձ”
  4. ؔ਺Λఆٛ͢Δ // վߦ͢ΔͱΤϥʔʹͳΔͷͰҰߦͰॻ͘͜ͱ (lldb) po func $getText() -> String {

    return “AKIBA.swift×SwiftѪ޷ձ” ɹ} (lldb) po $getText() “AKIBA.swift×SwiftѪ޷ձ”
  5. UIImage ΛϑΝΠϧʹग़ྗ͢Δ (lldb) po let $path = “/Users/dealforest/lldb.png” (lldb) po

    let $image = UIImage(named: “sample”) (lldb) po let $data = UIImagePNGRepresentation($image)! (lldb) po $data.writeToFile($path, atomically: true)
  6. ͕

  7. ؔ਺ʹ͢Δ - before (lldb) po let $path = “/Users/dealforest/lldb.png” (lldb)

    po let $image = UIImage(named: “sample”) (lldb) po let $data = UIImagePNGRepresentation($image)! (lldb) po $data.writeToFile($path, atomically: true)
  8. ؔ਺ʹ͢Δ - after // վߦ͢ΔͱΤϥʔʹͳΔͷͰҰߦͰॻ͘͜ͱ (lldb) po func $saveImage(image: UImage)

    { let path = “/Users/dealforest/lldb.png”; let data = UIImagePNGRepresentation(image)!; data.writeToFile(path, atomically: true); } (lldb) po $saveImage(UIImage(named: “sample”))
  9. ؔ਺ʹ͢Δ // վߦ͢ΔͱΤϥʔʹͳΔͷͰҰߦͰॻ͘͜ͱ (lldb) po func $saveImage(image: UImage) { let

    path = “/Users/dealforest/lldb.png”; let data = UIImagePNGRepresentation(image)!; data.writeToFile(path, atomically: true); } (lldb) po $saveImage(UIImage(named: “sample”))
  10. LLDB Plugin ʹ͢Δ #!/usr/bin/env python import lldb def save_image(debugger, command,

    result, internal_dict): frame = lldb.debugger.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame() result = frame.EvaluateExpression(command) target = result.GetLocation() expr = "expr -l objc++ -- (NSData *)UIImagePNGRepresentation((id)" + target + ")" frame.EvaluateExpression(expr) imagePath = '/Users/dealforest/lldb.png' saveImageTemplate = 'expr -l objc++ -- (void) [(NSData *){} writeToFile:@"{}" atomically:YES];' saveImageExpr = createImageFormatStr.format(result.GetName(), imagePath) lldb.debugger.HandleCommand(saveImageExpr) def __lldb_init_module(debugger,internal_dict): debugger.HandleCommand("command script add -f save_image.save_image save_image") print"save_image command enabled." save_image.py
  11. LLDB Plugin ʹ͢Δ #!/usr/bin/env python import lldb def save_image(debugger, command,

    result, internal_dict): frame = lldb.debugger.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame() result = frame.EvaluateExpression(command) target = result.GetLocation() expr = "expr -l objc++ -- (NSData *)UIImagePNGRepresentation((id)" + target + ")" frame.EvaluateExpression(expr) imagePath = '/Users/dealforest/lldb.png' saveImageTemplate = 'expr -l objc++ -- (void) [(NSData *){} writeToFile:@"{}" atomically:YES];' saveImageExpr = createImageFormatStr.format(result.GetName(), imagePath) lldb.debugger.HandleCommand(saveImageExpr) def __lldb_init_module(debugger,internal_dict): debugger.HandleCommand("command script add -f save_image.save_image save_image") print"save_image command enabled." ίϚϯυͷఆٛ save_image.py
  12. LLDB Plugin ʹ͢Δ #!/usr/bin/env python import lldb def save_image(debugger, command,

    result, internal_dict): frame = lldb.debugger.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame() result = frame.EvaluateExpression(command) target = result.GetLocation() expr = "expr -l objc++ -- (NSData *)UIImagePNGRepresentation((id)" + target + ")" frame.EvaluateExpression(expr) imagePath = '/Users/dealforest/lldb.png' saveImageTemplate = 'expr -l objc++ -- (void) [(NSData *){} writeToFile:@"{}" atomically:YES];' saveImageExpr = createImageFormatStr.format(result.GetName(), imagePath) lldb.debugger.HandleCommand(saveImageExpr) def __lldb_init_module(debugger,internal_dict): debugger.HandleCommand("command script add -f save_image.save_image save_image") print"save_image command enabled." UIImage ͷ pointer Λऔಘ save_image.py
  13. LLDB Plugin ʹ͢Δ #!/usr/bin/env python import lldb def save_image(debugger, command,

    result, internal_dict): frame = lldb.debugger.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame() result = frame.EvaluateExpression(command) target = result.GetLocation() expr = "expr -l objc++ -- (NSData *)UIImagePNGRepresentation((id)" + target + ")" frame.EvaluateExpression(expr) imagePath = '/Users/dealforest/lldb.png' saveImageTemplate = 'expr -l objc++ -- (void) [(NSData *){} writeToFile:@"{}" atomically:YES];' saveImageExpr = createImageFormatStr.format(result.GetName(), imagePath) lldb.debugger.HandleCommand(saveImageExpr) def __lldb_init_module(debugger,internal_dict): debugger.HandleCommand("command script add -f save_image.save_image save_image") print"save_image command enabled." UIImage Λ NSData ʹม׵ save_image.py
  14. LLDB Plugin ʹ͢Δ #!/usr/bin/env python import lldb def save_image(debugger, command,

    result, internal_dict): frame = lldb.debugger.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame() result = frame.EvaluateExpression(command) target = result.GetLocation() expr = "expr -l objc++ -- (NSData *)UIImagePNGRepresentation((id)" + target + ")" frame.EvaluateExpression(expr) imagePath = '/Users/dealforest/lldb.png' saveImageTemplate = 'expr -l objc++ -- (void) [(NSData *){} writeToFile:@"{}" atomically:YES];' saveImageExpr = createImageFormatStr.format(result.GetName(), imagePath) lldb.debugger.HandleCommand(saveImageExpr) def __lldb_init_module(debugger,internal_dict): debugger.HandleCommand("command script add -f save_image.save_image save_image") print"save_image command enabled." NSData ΛϑΝΠϧʹอଘ save_image.py
  15. LLDB Plugin ʹ͢Δ #!/usr/bin/env python import lldb def save_image(debugger, command,

    result, internal_dict): lldb.debugger.HandleCommand(""" expr -l swift -- func $saveImage(image: UIImage) { let $data = UIImagePNGRepresentation($image)! $data.writeToFile("/Users/dealforest/lldb.png", atomically: true) } """.strip()) expr = 'expr -l swift -- $saveImage(' + command + ')' lldb.debugger.HandleCommand(expr) def __lldb_init_module(debugger,internal_dict): debugger.HandleCommand("command script add -f save_image.save_image save_image") print"save_image command enabled." save_image.py
  16. LLDB Plugin ʹ͢Δ lldb.debugger.HandleCommand(""" expr -l swift -- func $saveImage(image:

    UIImage) { ɹɹɹɹɹɹɹɹɹ ɹ let $path = “/Users/dealforest/lldb.png” let $data = UIImagePNGRepresentation($image)! $data.writeToFile(path, atomically: true) } """.strip()) save_image.py