如何调试WebKit2GTK +扩展 [英] How to debug WebKit2GTK+ extensions
问题描述
我正在尝试使WebKit2GTK +扩展正常工作,这是一个简单的扩展,仅在创建页面时才会打印到控制台中. 这是我的项目结构:
I am trying to get WebKit2GTK+ Extensions to work, it is a simple extension that will just print into the console when a page is created. Here is my project structure:
-bin
-images
-include
-lib
--webextension
---libwebextension.so
---libwebextension.so.1
---libwebextension.so.1.0
---webextension.cpp
-src
--gtk
---gtk_manager.cpp
--main.cpp
gtk_manager.cpp文件包含头文件的实现,只有init()函数很重要(稍后会介绍)
The gtk_manager.cpp files contains the implementation of the header file, only the init() function will matter (will get to that in a little bit)
webextension.cpp
webextension.cpp
#include <webkit2/webkit-web-extension.h>
#include <iostream>
void
web_page_created_callback (WebKitWebExtension *extension,
WebKitWebPage *web_page,
gpointer user_data)
{
g_print ("Page %d created for %s\n",
webkit_web_page_get_id (web_page),
webkit_web_page_get_uri (web_page));
}
G_MODULE_EXPORT void
webkit_web_extension_initialize (WebKitWebExtension *extension)
{
std::cout << "extension hi\n";
g_signal_connect (extension, "page-created",
G_CALLBACK (web_page_created_callback),
NULL);
}
void hi()
{
g_print("hi");
}
运行时工作期间的导出和动态链接,因为我可以从gtk_manager.cpp的init()
方法调用hi()
. webkit_web_extension_initialize()
没有显示任何正在工作/被呼叫的迹象,因为控制台未打印"extension hi".
The exportation and dynamic linking during runtime work, as I can call hi()
from gtk_manager.cpp's init()
method. webkit_web_extension_initialize()
is not showing any signs of working/being called, because "extension hi" is not printed into the console.
gtk_manager.cpp(gtk/gtk.h,glib.h和webkit2/webkit2.h已从gtk_manager.h包含在include文件夹中)
gtk_manager.cpp (gtk/gtk.h, glib.h, and webkit2/webkit2.h are being included from gtk_manager.h in include folder)
#include "gtk/gtk_manager.h"
#include <iostream>
void initialize_web_extensions(WebKitWebContext*, gpointer);
void GTKManager::init(int argc, char* args[])
{
g_signal_connect(webkit_web_context_get_default(), "initialize-web-extensions", G_CALLBACK(initialize_web_extensions), NULL);
gtk_init(&argc, &args);
/* other code */
}
/* other methods / functions */
void initialize_web_extensions(WebKitWebContext* context, gpointer userData)
{
static guint uniqueId = 0;
webkit_web_context_set_web_extensions_directory(context, "/abs/path/to/app/lib/webextension");
webkit_web_context_set_web_extensions_initialization_user_data(context, g_variant_new_uint32(uniqueId++));
hi(); // This is from webextension.cpp, it is called successfully
}
如果需要更多信息以找到解决方案,我将编辑此问题.
I will edit this question if more information is needed to find a solution.
这些是我正在使用的资源:
These are the resources I am using:
- https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebExtension.html
- https://blogs.igalia. com/carlosgc/2013/09/10/webkit2gtk-web-process-extensions/
- https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebExtension.html
- https://blogs.igalia.com/carlosgc/2013/09/10/webkit2gtk-web-process-extensions/
推荐答案
由于它是C ++,因此可能是由于名称修改所致.尝试在webkit_web_extension_initialize函数的前面加上外部字符"C".例如:
Since it's C++ it could be due to name mangling. Try to prefix the webkit_web_extension_initialize function with extern "C". For example:
extern "C" G_MODULE_EXPORT void
webkit_web_extension_initialize (WebKitWebExtension *extension)
{
std::cout << "extension hi\n";
/* your code */
}
您可以使用readelf或objdump列出所有导出的符号,并查看它们的名称是否错误.
You can use readelf or objdump to list all exported symbols and see if they have mangled names.
这篇关于如何调试WebKit2GTK +扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!