Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于naive在macos系统上的debug问题 #259

Closed
ghost opened this issue Feb 9, 2022 · 12 comments
Closed

关于naive在macos系统上的debug问题 #259

ghost opened this issue Feb 9, 2022 · 12 comments

Comments

@ghost
Copy link

ghost commented Feb 9, 2022

问题一:
以debug方式编译macos M1时,出现link如下错误!

ld64.lld: error: undefined symbol: perfetto::TracedValue::WriteDictionary() &&
>>> referenced by obj/net/net/http_response_headers.o
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

我的解决方式·,移除掉L1399-L1401,即可通过link编译:
https://github.com/klzgrad/naiveproxy/blob/master/src/net/http/http_response_headers.cc#L1399-L1401

void HttpResponseHeaders::WriteIntoTrace(perfetto::TracedValue context) const {
}

问题二:

在macos上,如果对naive进行debug运行,则会进程崩溃。

(base) air@airdeMacBook-Air Debug % ./naive config.json 
[0209/203240.690779:INFO:naive_proxy_bin.cc(414)] Proxying via https://example.cc(PS: 这个代理服务链接实际上时真实链接,这里为了不泄露个人链接而写的假的链接)
[0209/203240.691345:FATAL:cert_net_fetcher_url_request.cc(777)] Check failed: !context_. 
0   libbase.dylib                       0x0000000101c35850 base::debug::CollectStackTrace(void**, unsigned long) + 36
1   libbase.dylib                       0x00000001018fb16c base::debug::StackTrace::StackTrace(unsigned long) + 92
2   libbase.dylib                       0x00000001018fb200 base::debug::StackTrace::StackTrace(unsigned long) + 36
3   libbase.dylib                       0x00000001018fb1cc base::debug::StackTrace::StackTrace() + 40
4   libbase.dylib                       0x000000010195a094 logging::LogMessage::~LogMessage() + 180
5   libbase.dylib                       0x000000010195ae7c logging::LogMessage::~LogMessage() + 28
6   libbase.dylib                       0x000000010195aea8 logging::LogMessage::~LogMessage() + 28
7   libbase.dylib                       0x00000001018b4a24 logging::CheckError::~CheckError() + 60
8   libbase.dylib                       0x00000001018b4478 logging::CheckError::~CheckError() + 28
9   libnet.dylib                        0x00000001041e6f20 net::CertNetFetcherURLRequest::~CertNetFetcherURLRequest() + 192
10  libnet.dylib                        0x00000001041e7044 net::CertNetFetcherURLRequest::~CertNetFetcherURLRequest() + 28
11  libnet.dylib                        0x00000001041e7070 net::CertNetFetcherURLRequest::~CertNetFetcherURLRequest() + 28
12  libnet.dylib                        0x000000010410e028 void base::RefCountedThreadSafe<net::CertNetFetcher, base::DefaultRefCountedThreadSafeTraits<net::CertNetFetcher> >::DeleteInternal<net::CertNetFetcher>(net::CertNetFetcher const*) + 48
13  libnet.dylib                        0x000000010410dfec base::DefaultRefCountedThreadSafeTraits<net::CertNetFetcher>::Destruct(net::CertNetFetcher const*) + 24
14  libnet.dylib                        0x000000010410dfc4 base::RefCountedThreadSafe<net::CertNetFetcher, base::DefaultRefCountedThreadSafeTraits<net::CertNetFetcher> >::Release() const + 48
15  libnet.dylib                        0x000000010410df88 scoped_refptr<net::CertNetFetcher>::Release(net::CertNetFetcher*) + 28
16  libnet.dylib                        0x000000010410df58 scoped_refptr<net::CertNetFetcher>::~scoped_refptr() + 56
17  libnet.dylib                        0x000000010410aa78 scoped_refptr<net::CertNetFetcher>::~scoped_refptr() + 28
18  libnet.dylib                        0x000000010410f344 net::CertVerifyProc::CreateSystemVerifyProc(scoped_refptr<net::CertNetFetcher>) + 76
19  libnet.dylib                        0x000000010410a7cc net::CertVerifier::CreateDefaultWithoutCaching(scoped_refptr<net::CertNetFetcher>) + 156
20  libnet.dylib                        0x000000010410aae0 net::CertVerifier::CreateDefault(scoped_refptr<net::CertNetFetcher>) + 88
21  naive                               0x0000000100265824 net::(anonymous namespace)::BuildURLRequestContext((anonymous namespace)::Params const&, scoped_refptr<net::CertNetFetcherURLRequest>, net::NetLog*) + 580
22  naive                               0x0000000100263298 main + 1344
23  dyld                                0x00000001004050f4 start + 520

https://github.com/klzgrad/naiveproxy/blob/master/src/net/cert_net/cert_net_fetcher_url_request.cc#L779

如果将其改成 context_ = nullptr; 则解决该进程初次崩溃的问题(仅在macos上出现该问题,linux尚未测试,作者也可以测试下)。

CertNetFetcherURLRequest::~CertNetFetcherURLRequest() {
 }

但实际连接时,就会发现无法连接上,SSL证书错误!

[0209/203832.169691:INFO:naive_proxy_bin.cc(414)] Proxying via https://example.cc(PS: 这个代理服务链接实际上时真实链接,这里为了不泄露个人链接而写的假的链接)
[0209/203832.172025:INFO:naive_proxy_bin.cc(550)] Listening on 0.0.0.0:2080
[0209/203832.530671:INFO:naive_connection.cc(250)] Connection 1 to www.google.com:443
[0209/203833.307258:ERROR:ssl_client_socket_impl.cc(996)] handshake failed; returned -1, SSL error code 1, net_error -207
[0209/203833.307816:INFO:naive_proxy.cc(182)] Connection 1 closed: ERR_PROXY_CERTIFICATE_INVALID
[0209/203833.308866:INFO:naive_connection.cc(250)] Connection 2 to www.google.com:443
[0209/203834.273871:ERROR:ssl_client_socket_impl.cc(996)] handshake failed; returned -1, SSL error code 1, net_error -207
[0209/203834.275628:INFO:naive_proxy.cc(182)] Connection 2 closed: ERR_PROXY_CERTIFICATE_INVALID
[0209/203835.300409:INFO:naive_connection.cc(250)] Connection 3 to www.google.com:443
[0209/203835.551433:INFO:naive_connection.cc(250)] Connection 4 to www.google.com:443
[0209/203835.924571:ERROR:ssl_client_socket_impl.cc(996)] handshake failed; returned -1, SSL error code 1, net_error -207
[0209/203835.926246:INFO:naive_proxy.cc(182)] Connection 4 closed: ERR_PROXY_CERTIFICATE_INVALID
[0209/203835.927915:INFO:naive_connection.cc(250)] Connection 5 to www.google.com:443
[0209/203836.568314:ERROR:ssl_client_socket_impl.cc(996)] handshake failed; returned -1, SSL error code 1, net_error -207
[0209/203836.569404:INFO:naive_proxy.cc(182)] Connection 5 closed: ERR_PROXY_CERTIFICATE_INVALID
[0209/203836.577102:ERROR:ssl_client_socket_impl.cc(996)] handshake failed; returned -1, SSL error code 1, net_error -207
[0209/203836.578596:INFO:naive_proxy.cc(182)] Connection 3 closed: ERR_PROXY_CERTIFICATE_INVALID

如果作者有macos环境可以复现下,我在macos M1上成功复现了该错误

@klzgrad
Copy link
Owner

klzgrad commented Feb 10, 2022

这些问题,非debug是否出现?

@ghost
Copy link
Author

ghost commented Feb 10, 2022

这些问题,非debug是否出现?

非debug似乎没出问题,但debug就会出现。

Done. Made 460 targets from 141 files in 1453ms
ninja: Entering directory `out/Debug'
[3258/3260] SOLINK libnet.dylib libnet.dylib.TOC
FAILED: libnet.dylib libnet.dylib.TOC 
if [ ! -e "./libnet.dylib" -o ! -e "./libnet.dylib.TOC" ] || /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool -l "./libnet.dylib" | grep -q LC_REEXPORT_DYLIB ; then TOOL_VERSION=1644360362 ../../build/toolchain/apple/linker_driver.py -Wcrl,strippath,/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip ../../third_party/llvm-build/Release+Asserts/bin/clang++ -shared  -Wl,-install_name,@rpath/"libnet.dylib" -fuse-ld=lld -Wl,--color-diagnostics -arch arm64 -no-canonical-prefixes -nostdlib++ -isysroot ../../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -mmacosx-version-min=10.11.0 -Wl,-ObjC -Wl,-rpath,@loader_path/. -Wl,-rpath,@loader_path/../../.. -o "./libnet.dylib" "@./libnet.dylib.rsp" && { /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool -l "./libnet.dylib" | grep LC_ID_DYLIB -A 5; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm -gPp "./libnet.dylib" | cut -f1-2 -d' ' | grep -v U$$; true; } > "./libnet.dylib.TOC"; else TOOL_VERSION=1644360362 ../../build/toolchain/apple/linker_driver.py -Wcrl,strippath,/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip ../../third_party/llvm-build/Release+Asserts/bin/clang++ -shared  -Wl,-install_name,@rpath/"libnet.dylib" -fuse-ld=lld -Wl,--color-diagnostics -arch arm64 -no-canonical-prefixes -nostdlib++ -isysroot ../../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -mmacosx-version-min=10.11.0 -Wl,-ObjC -Wl,-rpath,@loader_path/. -Wl,-rpath,@loader_path/../../.. -o "./libnet.dylib" "@./libnet.dylib.rsp" && { /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool -l "./libnet.dylib" | grep LC_ID_DYLIB -A 5; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm -gPp "./libnet.dylib" | cut -f1-2 -d' ' | grep -v U$$; true; } > "./libnet.dylib.tmp" && if ! cmp -s "./libnet.dylib.tmp" "./libnet.dylib.TOC"; then mv "./libnet.dylib.tmp" "./libnet.dylib.TOC" ; fi; fi
ld64.lld: error: undefined symbol: perfetto::TracedValue::WriteDictionary() &&
>>> referenced by obj/net/net/http_response_headers.o
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Traceback (most recent call last):
  File "/Users/macbook/Desktop/debug/naiveproxy/src/out/Debug/../../build/toolchain/apple/linker_driver.py", line 341, in <module>
    LinkerDriver(sys.argv).run()
  File "/Users/macbook/Desktop/debug/naiveproxy/src/out/Debug/../../build/toolchain/apple/linker_driver.py", line 117, in run
    subprocess.check_call(compiler_driver_args, env=env)
  File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 373, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['../../third_party/llvm-build/Release+Asserts/bin/clang++', '-shared', '-Wl,-install_name,@rpath/libnet.dylib', '-fuse-ld=lld', '-Wl,--color-diagnostics', '-arch', 'arm64', '-no-canonical-prefixes', '-nostdlib++', '-isysroot', '../../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk', '-mmacosx-version-min=10.11.0', '-Wl,-ObjC', '-Wl,-rpath,@loader_path/.', '-Wl,-rpath,@loader_path/../../..', '-o', './libnet.dylib', '@./libnet.dylib.rsp']' returned non-zero exit status 1.
[3259/3260] CXX obj/net/naive/naive_proxy_bin.o
ninja: build stopped: subcommand failed.



@ghost
Copy link
Author

ghost commented Feb 10, 2022

我建议作者使用debug方式编译下,现在release编译是看不出问题的。

@ghost
Copy link
Author

ghost commented Feb 10, 2022

这些问题,非debug是否出现?

如果以debug方式编译,obj/net/net/http_response_headers.o 是没法link的

@ghost
Copy link
Author

ghost commented Feb 10, 2022

我看到作者打了三个path,目前我正在macos上debug编译,一会有结果我会告知您:
base: Export trace event stubs for debug build[]
Fix build.sh with debug

Disable cert net fetcher on Mac[]

@ghost
Copy link
Author

ghost commented Feb 10, 2022

这些问题,非debug是否出现?

经过测试,上述三个补丁
base: Export trace event stubs for debug build[]
Fix build.sh with debug

Disable cert net fetcher on Mac[]

可正常编译和link,但实际运行出现如下状况:

[0210/221338.485694:INFO:naive_connection.cc(251)] Connection 1 to www.google.com:443
[0210/221338.687150:INFO:naive_proxy.cc(182)] Connection 1 closed: ERR_PROXY_CONNECTION_FAILED
[0210/221338.688243:INFO:naive_connection.cc(251)] Connection 2 to www.google.com:443
[0210/221338.690565:INFO:naive_proxy.cc(182)] Connection 2 closed: ERR_PROXY_CONNECTION_FAILED
[0210/221338.691789:INFO:naive_connection.cc(251)] Connection 3 to www.google.com:443
[0210/221338.695706:INFO:naive_proxy.cc(182)] Connection 3 closed: ERR_PROXY_CONNECTION_FAILED
[0210/221338.696926:INFO:naive_connection.cc(251)] Connection 4 to www.google.com:443
[0210/221338.699870:INFO:naive_proxy.cc(182)] Connection 4 closed: ERR_PROXY_CONNECTION_FAILED
[0210/221339.179320:INFO:naive_connection.cc(251)] Connection 5 to www.google.com:443

@klzgrad
Copy link
Owner

klzgrad commented Feb 10, 2022

ERR_PROXY_CONNECTION_FAILED
用--log-net-log=或者--ssl-key-log-file=去诊断

@ghost
Copy link
Author

ghost commented Feb 10, 2022

ERR_PROXY_CONNECTION_FAILED 用--log-net-log=或者--ssl-key-log-file=去诊断

LLDB 调试,直接 * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1

(base) macbook@macbookdeMacBook-Air src % lldb ./out/Debug/naive ./out/Debug/config.json
(lldb) target create "./out/Debug/naive"
Current executable set to '/Users/macbook/Desktop/debug/naiveproxy/src/out/Debug/naive' (arm64).
(lldb) settings set -- target.run-args  "./out/Debug/config.json"
(lldb) b naive_proxy_bin.cc:464
Breakpoint 1: where = naive`main + 68 at naive_proxy_bin.cc:464:3, address = 0x00000001000168b0
(lldb) run
Process 98646 launched: '/Users/macbook/Desktop/debug/naiveproxy/src/out/Debug/naive' (arm64)
Process 98646 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x00000001000168b0 naive`main(argc=2, argv=0x000000016fdff2f8) at naive_proxy_bin.cc:464:3
Target 0: (naive) stopped.
(lldb) 


@ghost
Copy link
Author

ghost commented Feb 10, 2022

ERR_PROXY_CONNECTION_FAILED 用--log-net-log=或者--ssl-key-log-file=去诊断

ssl-key-log-file 则空输出,啥都没有

Repository owner deleted a comment Feb 10, 2022
@klzgrad
Copy link
Owner

klzgrad commented Feb 10, 2022

这个要你自己去看,不要发到这里。netlog用https://netlog-viewer.appspot.com/ 去看,ssl-key-log-file是用来给Wireshark解码TLS用的,要结合Wireshark看。

@ghost
Copy link
Author

ghost commented Feb 10, 2022

这个要你自己去看,不要发到这里。netlog用https://netlog-viewer.appspot.com/ 去看,ssl-key-log-file是用来给Wireshark解码TLS用的,要结合Wireshark看。

我换了个xcode编译,现在OK了。您打的三个补丁没问题的,可以解决debug问题了(debug模式下正常进行代理)。

@ghost
Copy link
Author

ghost commented Feb 10, 2022

这个要你自己去看,不要发到这里。netlog用https://netlog-viewer.appspot.com/ 去看,ssl-key-log-file是用来给Wireshark解码TLS用的,要结合Wireshark看。

目前该帖可以关闭了。您打的三个补丁是正确的,解决了

@ghost ghost closed this as completed Feb 10, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant