Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


Sample output for the pretty printer:

$1 = directory: "file:///home/catalin/libreoffice/a_dir"
$2 = file: "file:///home/catalin/libreoffice/s1.ods"
$3 = link: "file:///home/catalin/libreoffice/link.patch" ->
"file:///home/catalin/libreoffice/patches/0001-Fix-cppcheck-possible-null-dereference-in-ScMyCellIn.patch"
$4 = fifo: "file:///home/catalin/libreoffice/some_fifo"
$5 = directory: <invalid file url>
$6 = link: <invalid file url> ->
"file:///home/catalin/libreoffice/patches/0001-Fix-cppcheck-possible-null-dereference-in-ScMyCellIn.patch"

$5 is a directory but osl_FileStatus_Mask_FileURL was not set when
retrieving it so the file url is invalid
Similarly, for $6 osl_FileStatus_Mask_FileURL is not set but
osl_FileStatus_Mask_FileURL is therefore the link target is valid and
can be printed
From 3f11d4862254238ee39fcc64ef53e8d12e431cd5 Mon Sep 17 00:00:00 2001
From: Catalin Iacob <iacobcatalin@gmail.com>
Date: Wed, 29 Feb 2012 22:25:13 +0100
Subject: [PATCH] fdo #46446: add python gdb helpers for osl::FileBase

---
 solenv/gdb/libreoffice/sal.py |   65 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/solenv/gdb/libreoffice/sal.py b/solenv/gdb/libreoffice/sal.py
index df87ed5..56a9752 100644
--- a/solenv/gdb/libreoffice/sal.py
+++ b/solenv/gdb/libreoffice/sal.py
@@ -26,6 +26,7 @@
 # instead of those above.
 
 import gdb
+import gdb.types
 
 from libreoffice.util import printing
 from libreoffice.util.string import StringPrinterHelper
@@ -90,6 +91,69 @@ class RtlReferencePrinter(object):
         else:
             return "empty %s" % self.typename
 
+class OslFileStatusPrinter(object):
+    '''Prints oslFileStatus'''
+
+    def __init__(self, typename, val):
+        self.val = val
+
+    def to_string(self):
+        osl_file_type = gdb.lookup_type('oslFileType').strip_typedefs()
+        fields_to_enum_val = gdb.types.make_enum_dict(osl_file_type)
+
+        etype = self.field_val_if_valid('eType')
+        if etype is not None:
+            pretty_etype = '<unknown type>' # in case it's not one of the fields
+
+            for field_name, field_val in fields_to_enum_val.iteritems():
+                if etype == field_val:
+                    pretty_etype = self.pretty_file_type(field_name)
+        else:
+            pretty_etype = '<invalid type>'
+
+        file_url = self.field_val_if_valid('ustrFileURL')
+        if file_url is not None:
+            pretty_file_url = str(file_url.dereference())
+        else:
+            pretty_file_url = '<invalid file url>'
+
+        pretty_file_status = pretty_etype + ': ' + pretty_file_url
+
+        # for links append the link target if valid
+        if etype == fields_to_enum_val['osl_File_Type_Link']:
+            link_target = self.field_val_if_valid('ustrLinkTargetURL')
+            if link_target is None:
+                pretty_link_target = '<invalid link target>'
+            else:
+                pretty_link_target = str(link_target.dereference())
+
+            pretty_file_status += ' -> ' + pretty_link_target
+
+        return pretty_file_status
+
+    def pretty_file_type(self, file_type_name):
+        if file_type_name != 'osl_File_Type_Regular':
+            return file_type_name.replace('osl_File_Type_', '').lower()
+        else:
+            return 'file' # regular is not very descriptive, file is better
+
+    def field_val_if_valid(self, field):
+        mask_for_field = {'eType': 0x00000001,
+                          'uAttributes': 0x00000002,
+                          'aCreationTime': 0x00000010,
+                          'aAccessTime': 0x00000020,
+                          'aModifyTime': 0x00000040,
+                          'uFileSize': 0x00000080,
+                          'ustrFileName': 0x00000100,
+                          'ustrFileURL': 0x00000200,
+                          'ustrLinkTargetURL': 0x00000400}
+
+        valid_fields = self.val['uValidFields']
+        if valid_fields & mask_for_field[field]:
+            return self.val[field]
+        else:
+            return None
+
 printer = None
 
 def build_pretty_printers():
@@ -109,6 +173,7 @@ def build_pretty_printers():
 
     # other stuff
     printer.add('rtl::Reference', RtlReferencePrinter)
+    printer.add('_oslFileStatus', OslFileStatusPrinter)
 
     return printer
 
-- 
1.7.9.2


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.