Closed Bug 1179278 Opened 9 years ago Closed 8 years ago

JS GDB pretty-printers: JSObject printer is flummoxed by bad UTF-8 in class names

Categories

(Core :: JavaScript Engine, defect)

All
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla48
Tracking Status
firefox48 --- fixed

People

(Reporter: jimb, Assigned: jimb)

Details

Attachments

(1 file, 3 obsolete files)

When printing a JSObject, bogus pointers can lead mozilla.JSObject.JSObjectPtrOrRef.summary to try to print bad data as a class name. This leads to unfortunate output printing stack frames:

Python Exception <type 'exceptions.UnicodeDecodeError'> 'utf8' codec can't decode byte 0xc7 in position 0: invalid continuation byte: 
#30 0x000000000055f666 in js::MapObject::initClass (cx=0x7ffff611b330, obj=) at /home/jimb/moz/dbg/js/src/builtin/MapObject.cpp:1086

I think the solution is to specify an encoding in the call to gdb.Value.string in which all byte strings are valid, like Latin-1, rather than UTF-8.
Since in practice class names are ASCII, that would make sense.
Assignee: nobody → jimb
Status: NEW → ASSIGNED
Attachment #8628498 - Flags: review?(ttromey)
Doc tweak.
Attachment #8628498 - Attachment is obsolete: true
Attachment #8628498 - Flags: review?(ttromey)
Attachment #8628499 - Flags: review?(ttromey)
Comment on attachment 8628499 [details] [diff] [review]
Handle encoding errors when trying to print JSObject class names.

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

::: js/src/gdb/mozilla/JSObject.py
@@ -30,5 @@
>  
>      def summary(self):
>          group = deref(self.value['group_'])
>          classp = group['clasp_']
> -        class_name = classp['name'].string()

It isn't well-documented, but .string() uses the python codecs and consequently (as you found) errors when decoding invalid data.

On the other hand, .lazy_string() uses the gdb codecs and string-printing code, and conversion is done when the value is actually printed.  In a case like this it should result in something like <incomplete sequence \c7>.

So, I suggest trying that here.
Attachment #8628499 - Flags: review?(ttromey) → review+
Let's land this!
Flags: needinfo?(jimb)
I haven't implemented the changes Tom suggested.

Tom, in comment 4, are you saying that simply changing the .string() to .lazy_string() should work?
Flags: needinfo?(jimb) → needinfo?(ttromey)
(In reply to Jim Blandy :jimb from comment #6)
> I haven't implemented the changes Tom suggested.
> 
> Tom, in comment 4, are you saying that simply changing the .string() to
> .lazy_string() should work?

... that is, calling .lazy_string() *instead* of .string() and the following code?

        class_name = class_name.string(encoding='latin_1')	
        class_name = class_name.encode(encoding='ascii', errors='backslashreplace')
	
(Why don't you just *try* it, Jim? You have tests...)
(In reply to Tom Tromey :tromey from comment #4)
> On the other hand, .lazy_string() uses the gdb codecs and string-printing
> code, and conversion is done when the value is actually printed.  In a case
> like this it should result in something like <incomplete sequence \c7>.

I need the class name as a Python string: I compare it to other Python strings, and pass it as an argument to "...".format. The Python 'str' function gives me garbage like <gdb.LazyString object at 0x7f12fc693240>.

In the end, I just took matters into my own hands...
Attachment #8628499 - Attachment is obsolete: true
Attachment #8728198 - Flags: review?(ttromey)
In the end, what I want is something pretty weird: it's like a string literal, in that it uses source-code things like \xc7, but with no quotes around it.
Actually, I like this version better.
Attachment #8728198 - Attachment is obsolete: true
Attachment #8728198 - Flags: review?(ttromey)
Attachment #8728201 - Flags: review?(ttromey)
Comment on attachment 8728201 [details] [diff] [review]
Handle encoding errors when trying to print JSObject class names.

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

Stealing -- it's the least I can do. r=me.
Attachment #8728201 - Flags: review?(ttromey) → review+
Ok, sorry, I didn't understand the subtlety here about the quotes.
Anyway it seems reasonable enough to me.
Flags: needinfo?(ttromey)
OS: Unspecified → Linux
Hardware: Unspecified → All
Target Milestone: --- → mozilla48
https://hg.mozilla.org/mozilla-central/rev/37e64a9ae974
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: