我正在尝试调试我用gdb编写的服务器,因为它在非常特殊和罕见的条件下进行了段错误.
有什么方法可以让gdb在后台运行(通过安静或批处理模式?),跟随子项(因为我的服务器是守护进程并从主PID中分离)并自动转储核心和回溯(到指定的文件) )一旦程序崩溃了?
虽然我已经编程了很长一段时间,但是当涉及耦合对象时,我似乎总是把头撞到墙上,所以我想知道是否有人有任何资源或我可以遵循的黄金规则.
让我举一个小例子,没有特别的语言......
class Person {
private int personnel_id
private String first_name;
private String last_name;
private int personnel_level;
//Lab labs[4]; <- Lab(s) the Person works in
}
class Lab {
private int lab_id;
private String lab_name;
//Person[99] personnel; <- Person(s) working in the Lab
}
Run Code Online (Sandbox Code Playgroud)
让我们暂时忽略ctors/setters/getters/dtors并只是实例化一些东西......
Person people = new Person[1500];
Lab labs = new Lab[10];
Run Code Online (Sandbox Code Playgroud)
我的问题是......这里最好的做法是什么......
people["Gordon Freeman"].blewUp((Lab)"Black Mesa");
-> returns T/F
Run Code Online (Sandbox Code Playgroud)
要么...
labs["BlackMesa"].blownUpBy((Person)"Gordon Freeman");
-> returns T/F
Run Code Online (Sandbox Code Playgroud)
或者它甚至不重要:S
我正在研究的现实生活中的例子要复杂得多.每当Person做某事时,每个人都Lab需要得到通知等等,而我只想弄清楚我是否有任何原则可以在这里申请.
如果我们查看Java标准 §14.7,我们会看到语句可能有标签前缀,例如:
LabeledStatement:
标识符:声明
理论上,标签应该能够标记任何后续声明.因此,例如,以下编译:
public class Test {
public static void main(String[] args) {
hello:
return;
}
}
Run Code Online (Sandbox Code Playgroud)
直觉上,这也编译:
public class Test {
int i;
public static void main(String[] args) {
Test t = new Test();
label:
t.i = 2;
}
}
Run Code Online (Sandbox Code Playgroud)
但下列情况不能编译:
public class Test {
public static void main(String[] args) {
oops:
int k = 3;
}
}
Run Code Online (Sandbox Code Playgroud)
即使这样做(注意范围括号):
public class Test {
public static void main(String[] args) {
oops:
{
int k = …Run Code Online (Sandbox Code Playgroud) 我正在编写/将C++ HTTP事件服务器移植到Java.我想知道用Jetty,Tomcat,任何其他服务器或本机实现彗星的最佳范例是什么.
可伸缩性是绝对必须的,因为我正在开发一种每个客户端最多使用3个并发连接的新协议.
任何帮助表示赞赏.
PS:如果可能的话,我也希望看到一些示例代码或教程..
我正在尝试在JavaScript中重载XMLHttpRequest.*方法,以便网页可以确定是否发生了Ajax请求而没有使用任何侵入式回调.现在,使用大多数JS框架时,这样的工作相对较好:
XMLHttpRequest.prototype.getResponseHeader = function() {
alert('O hai, looks like you made an AJAX request.');
}
Run Code Online (Sandbox Code Playgroud)
但是,有两个捕获:
xmlhttp.open("GET","simple.html",false);有没有什么方法JS可以镜像XMLHttpRequest.open()或任何方式,我可以链接到它.我已经尝试了一百万个范例(工厂,克隆,包装 - 最多导致无限递归),似乎没有任何工作.也许这是不可能的.有任何想法吗?
我开始研究JS的动态分析工具,我想不引人注目地描述整个环境.我基本上遍历各种上下文,深入挖掘对象,每次我点击一个函数,我都会陷入其中.现在,这种方法相对较好,除了在处理jQuery/prototype等库时它会中断.
到目前为止,这是我的代码(尽我所能评论):
var __PROFILER_global_props = new Array(); // visited properties
/**
* Hook into a function
* @name the name of the function
* @fn the reference to the function
* @parent the parent object
*/
function __PROFILER_hook(name, fn, parent) {
//console.log('hooking ' + name + ' ' + fn + ' ' + parent);
if (typeof parent == 'undefined')
parent = window;
for (var i in parent) {
// find the right function
if (parent[i] === fn) {
// …Run Code Online (Sandbox Code Playgroud) 假设以下功能:
int binaryTree::findHeight(node *n) {
if (n == NULL) {
return 0;
} else {
return 1 + max(findHeight(n->left), findHeight(n->right));
}
}
Run Code Online (Sandbox Code Playgroud)
treeHeight对于给定的二叉搜索树,相当标准的递归函数binaryTree.现在,我正在帮助一个朋友(他正在学习算法课程),我遇到了一个奇怪的问题,我无法100%向他解释这个功能.
将max定义为max(a,b) ((a)>(b)?(a):(b))(恰好是最大定义windef.h),递归函数变得怪异(它运行的n^n时间就像n树高一样).这显然使得检查具有3000个元素的树的高度非常非常长.
但是,如果max是通过模板定义的,就像std它一样,一切都很好.所以使用std::max修复他的问题.我只想知道原因.
另外,为什么countLeaves函数工作正常,使用相同的程序递归?
int binaryTree::countLeaves(node *n) {
if (n == NULL) {
return 0;
} else if (n->left == NULL && n->right == NULL) {
return 1;
} else {
return countLeaves(n->left) + countLeaves(n->right);
}
}
Run Code Online (Sandbox Code Playgroud)
是因为在返回三元函数时,值a => …
这可能看起来有点奇怪..但我需要评估/解析通过HTTP使用HTTP发送的块.
值得注意的是,HTTP流可能永远不会结束.有没有什么方法可以解析块,因为我用CURL 得到它们?
或者我是否必须采用一些自制的fsockopen()解决方案?
用代码更好地解释一下,有没有办法绕过这个错误?我试图模拟命名空间.
window.SomeNamespace = {
Notification: Backbone.Model.extend(),
Notifications: Backbone.Collection.extend({
model: SomeNamespace.Notification //error here. SomeNamespace is not defined
}),
};
Run Code Online (Sandbox Code Playgroud) 我正在编写这个javascript,它将在几个其他域上使用,这些域调用一个php脚本(仅在我的域上)来返回一个数组.我正在使用xmlhttp,它在我的域上测试时效果很好,但是一旦从单独的域放置或调用javascript它就会完全中断.有人知道如何跨域提出此请求吗?
注意:我必须执行一个奇怪的小黑客,允许我进行两次单独的调用,并确保它们在处理之前都返回.无论如何,这在我的域名上每次都能完美运行.
这是调用我的PHP代码的javascript文件
function getUrls(){
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
xmlhttp2 = new XMLHttpRequest();
}
else {
// code for IE5 and IE6
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
// code for IE5 and IE6
xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200 ) {
parsedJSONurls = JSON.parse(xmlhttp.responseText);
xmlhttp2.open("GET", "http://mydomain.com/connect.php?q=companies", true);
xmlhttp2.send();
}
}
xmlhttp2.onreadystatechange = function(){
if (xmlhttp2.readyState == 4 && xmlhttp2.status == …Run Code Online (Sandbox Code Playgroud) javascript php xmlhttprequest cross-domain same-origin-policy