Debugging Firefox – My first printf

The first time I ran firefox on debug mode, I noticed that when I double clicked on the Google textbox on the browser’s first page, the message:

WARNING: 1 sort operation has occurred for the SQL statement ’0x7f7f6e10d588′. See https://developer.mozilla.org/En/Storage/Warnings details: file /home/diogogmt/workspace/github-projects/mozilla-central/storage/src/mozStoragePrivateHelpers.cpp, line 139

appeared on the terminal.

First, I went to https://developer.mozilla.org/En/Storage/Warnings to check the details of the warning. It turns out that the warning message tells how many sort operations occurs in a SQL statement, it happens when an SQL query has an ORDER BY statement but does not use an INDEX.

After reading about the warning, I went to the mozStoragePrivateHelpers.cpp file to check which line was displaying the warning on the terminal.
This is the function where the warning is generated.

113 void
114 checkAndLogStatementPerformance(sqlite3_stmt *aStatement)
115 {
116   // Check to see if the query performed sorting operations or not.  If it
117   // did, it may need to be optimized!
118   int count = ::sqlite3_stmt_status(aStatement, SQLITE_STMTSTATUS_SORT, 1);
119   if (count 120     return;
121
122   const char *sql = ::sqlite3_sql(aStatement);
123
124   // Check to see if this is marked to not warn
125   if (::strstr(sql, "/* do not warn (bug "))
126     return;
127
128   nsCAutoString message;
129   message.AppendInt(count);
130   if (count == 1)
131     message.Append(" sort operation has ");
132   else
133     message.Append(" sort operations have ");
134   message.Append("occurred for the SQL statement '");
135   nsPrintfCString address("0x%p", aStatement);
136   message.Append(address);
137   message.Append("'.  Seeeeee https://developer.mozilla.org/En/Storage/Warnings "
138                  "details. DEBUG!!!!! My first printf!");
139   NS_WARNING(message.get());
140 }

On line 125, it checks if the warning should be suppressed.
On line 128, a nsCAutoString object is created
Some text is appended to the object, and on line 139 the warning is issued.

On line 137, I added some extra text just to see if it would be displayed on the terminal… and it did :)

**I tried to do an incremental build, since it takes more than an hour to build firefox on my laptop, but when I made the changes to the mozStoragePrivateHelpers.cpp file, and re-build only the storage component, it would still display the content of the old file. I had to build the whole project to get the changes working.
MDN Increment build



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.