Closed Bug 1014479 Opened 10 years ago Closed 10 years ago

JS gdb pretty printers broken on Ubuntu 13.10+

Categories

(Core :: JavaScript Engine, defect)

All
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla32

People

(Reporter: jandem, Assigned: bbouvier)

Details

Attachments

(1 file)

I tried to fix the string pretty printers for bug 1013917, but noticed gdb on Ubuntu 13.10 loads the Python script as Python 3 instead of Python 2. For instance, it complains about the |print "foo"| syntax. I changed that to print(...) but then it threw an exception somewhere in jsid.py

bbouvier confirmed he had/has the same problem on Ubuntu 13.10 and 14.04

Eventually I managed to install gdb 7.7 on OS X and used that to fix the pretty printers, but I really expected it to work out-of-the-box on the most popular Linux distro.
OS: All → Linux
Assignee: nobody → benj
Status: NEW → ASSIGNED
> ldd $(which gdb) | grep python
libpython3.4m.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython3.4m.so.1.0 (0x00007f834f9c1000)

Apparently, python3 is builtin within gdb in the latest ubuntu releases, so the obvious solution would be to convert all scripts to python3. I've discovered and used 2to3, which automatically does the job and it works nicely. However, before asking for review, I'd like to be sure that changes are compatible with python2.7, and I can't tell without rebuilding gdb. Feel free to try and provide some feedback here. In the meanwhile, I'll let the patch here for people using recent versions of gdb.
Comment on attachment 8426949 [details] [diff] [review]
Update js-gdb pretty printers to python3; NO REVIEW YET

Review of attachment 8426949 [details] [diff] [review]:
-----------------------------------------------------------------

I haven't tried it locally, but it looks mostly fine. r=me with these comments addressed.

::: js/src/gdb/mozilla/JSString.py
@@ +44,4 @@
>                  yield chars[i]
>  
>      def to_string(self):
> +        s = ''

Please change this back to u'' for Python2's sake. (The u is simply ignored in Python3.)

@@ +48,2 @@
>          for c in self.jschars():
> +            s += chr(c)

This is the only other thing that will break Python2. To accomodate both, please add the following magic incantation at the top of JSString.py:

try:
    chr(10000)             # UPPER RIGHT PENCIL
except ValueError as exc:  # yuck, we are in Python 2.x, so chr() is 8-bit
    chr = unichr           # replace with teh unicodes

This hack only affects chr() callers in that one file. It doesn't replace __builtins__.chr, which would be too much.

::: js/src/gdb/mozilla/jsid.py
@@ +39,1 @@
>                                   "neither struct nor integral type")

fix indentation

::: js/src/gdb/mozilla/jsval.py
@@ +167,5 @@
>          # Let self.magic_names be an array whose i'th element is the name of
>          # the i'th magic value.
>          d = gdb.types.make_enum_dict(gdb.lookup_type('JSWhyMagic'))
> +        self.magic_names = list(range(max(d.values()) + 1))
> +        for (k,v) in list(d.items()): self.magic_names[v] = k

Change `list(d.items())` back to `d.items()`.

(2to3 was being overprotective here.)
Attachment #8426949 - Flags: review+
https://hg.mozilla.org/mozilla-central/rev/642d007d1320
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla32
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: